@atlaskit/smart-card 17.7.6 → 17.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/cjs/hooks.js +13 -0
  3. package/dist/cjs/state/analytics/useSmartLinkAnalytics.js +2 -2
  4. package/dist/cjs/state/hooks-external/useSmartLinkActions.js +71 -0
  5. package/dist/cjs/utils/analytics/analytics.js +3 -2
  6. package/dist/cjs/utils/mocks.js +7 -1
  7. package/dist/cjs/version.json +1 -1
  8. package/dist/cjs/view/BlockCard/index.js +2 -2
  9. package/dist/cjs/view/CardWithUrl/component.js +12 -6
  10. package/dist/cjs/view/FlexibleCard/components/blocks/title-block/resolved/index.js +4 -2
  11. package/dist/cjs/view/FlexibleCard/components/container/index.js +5 -3
  12. package/dist/cjs/view/FlexibleCard/components/elements/link/index.js +3 -1
  13. package/dist/cjs/view/FlexibleCard/components/elements/media/index.js +12 -4
  14. package/dist/cjs/view/FlexibleCard/index.js +8 -3
  15. package/dist/es2019/hooks.js +1 -0
  16. package/dist/es2019/state/analytics/useSmartLinkAnalytics.js +1 -1
  17. package/dist/es2019/state/hooks-external/useSmartLinkActions.js +42 -0
  18. package/dist/es2019/utils/analytics/analytics.js +3 -2
  19. package/dist/es2019/utils/mocks.js +5 -0
  20. package/dist/es2019/version.json +1 -1
  21. package/dist/es2019/view/BlockCard/index.js +2 -2
  22. package/dist/es2019/view/CardWithUrl/component.js +11 -7
  23. package/dist/es2019/view/FlexibleCard/components/blocks/title-block/resolved/index.js +3 -1
  24. package/dist/es2019/view/FlexibleCard/components/container/index.js +5 -3
  25. package/dist/es2019/view/FlexibleCard/components/elements/link/index.js +3 -1
  26. package/dist/es2019/view/FlexibleCard/components/elements/media/index.js +37 -4
  27. package/dist/es2019/view/FlexibleCard/index.js +8 -3
  28. package/dist/esm/hooks.js +1 -0
  29. package/dist/esm/state/analytics/useSmartLinkAnalytics.js +2 -2
  30. package/dist/esm/state/hooks-external/useSmartLinkActions.js +54 -0
  31. package/dist/esm/utils/analytics/analytics.js +3 -2
  32. package/dist/esm/utils/mocks.js +5 -0
  33. package/dist/esm/version.json +1 -1
  34. package/dist/esm/view/BlockCard/index.js +2 -2
  35. package/dist/esm/view/CardWithUrl/component.js +13 -7
  36. package/dist/esm/view/FlexibleCard/components/blocks/title-block/resolved/index.js +4 -2
  37. package/dist/esm/view/FlexibleCard/components/container/index.js +5 -3
  38. package/dist/esm/view/FlexibleCard/components/elements/link/index.js +3 -1
  39. package/dist/esm/view/FlexibleCard/components/elements/media/index.js +12 -4
  40. package/dist/esm/view/FlexibleCard/index.js +8 -3
  41. package/dist/types/hooks.d.ts +1 -0
  42. package/dist/types/state/analytics/useSmartLinkAnalytics.d.ts +1 -1
  43. package/dist/types/state/hooks/useSmartLink.d.ts +1 -1
  44. package/dist/types/state/hooks-external/useSmartLinkActions.d.ts +45 -0
  45. package/dist/types/utils/analytics/analytics.d.ts +2 -2
  46. package/dist/types/utils/mocks.d.ts +5 -0
  47. package/dist/types/view/BlockCard/types.d.ts +1 -1
  48. package/dist/types/view/Card/types.d.ts +1 -1
  49. package/dist/types/view/FlexibleCard/components/blocks/title-block/types.d.ts +2 -0
  50. package/dist/types/view/FlexibleCard/components/container/types.d.ts +2 -0
  51. package/dist/types/view/FlexibleCard/components/elements/link/types.d.ts +2 -0
  52. package/dist/types/view/FlexibleCard/types.d.ts +1 -0
  53. package/hooks/package.json +7 -0
  54. package/package.json +3 -1
@@ -3,13 +3,46 @@ import React from 'react';
3
3
  import { css, jsx } from '@emotion/core';
4
4
  import ImageIcon from '../../common/image-icon';
5
5
 
6
- const styles = url => css`
6
+ /**
7
+ * Media: Image
8
+ * [aspect-ratio: 16 / 9] The context box is fixed to aspect ratio of 16:9.
9
+ * [object-fit: cover] The replaced content is sized to maintain
10
+ * its aspect ratio while filling the element's entire content box.
11
+ * If the object's aspect ratio does not match the aspect ratio of its box,
12
+ * then the object will be clipped to fit.
13
+ * [object-position] Center alignment of the selected replaced element's
14
+ * contents within the element's box.
15
+ */
16
+ const styles = css`
17
+ aspect-ratio: 16 / 9;
7
18
  display: flex;
8
- justify-content: center;
9
19
  width: 100%;
20
+
21
+ // fallback
22
+ @supports not (aspect-ratio: auto) {
23
+ padding-top: 56.25%; // 16:9 ratio (9 / 16 = 0.5625)
24
+ height: 0;
25
+ position: relative;
26
+ overflow: hidden;
27
+ }
28
+
10
29
  > img {
11
- max-width: 100%;
30
+ min-height: 100%;
31
+ min-width: 100%;
12
32
  max-height: 100%;
33
+ max-width: 100%;
34
+ object-fit: cover;
35
+ object-position: center center;
36
+
37
+ // fallback
38
+ @supports not (aspect-ratio: auto) {
39
+ position: absolute;
40
+ transform: translate(-50%, -50%);
41
+ left: 50%;
42
+ top: 50%;
43
+ width: auto;
44
+ height: auto;
45
+ }
13
46
  }
14
47
  `;
15
48
 
@@ -23,7 +56,7 @@ const Media = ({
23
56
  }
24
57
 
25
58
  return jsx("div", {
26
- css: styles(url),
59
+ css: styles,
27
60
  "data-smart-element-media": true,
28
61
  "data-testid": testId
29
62
  }, jsx(ImageIcon, {
@@ -10,7 +10,9 @@ const FlexibleCard = ({
10
10
  onAuthorize,
11
11
  renderers,
12
12
  ui,
13
- url
13
+ url,
14
+ onClick,
15
+ testId
14
16
  }) => {
15
17
  const {
16
18
  status: cardType,
@@ -21,9 +23,12 @@ const FlexibleCard = ({
21
23
  const retry = getRetryOptions(url, status, details, onAuthorize);
22
24
  return /*#__PURE__*/React.createElement(FlexibleUiContext.Provider, {
23
25
  value: context
24
- }, /*#__PURE__*/React.createElement(Container, _extends({}, ui, {
26
+ }, /*#__PURE__*/React.createElement(Container, _extends({
27
+ testId: testId
28
+ }, ui, {
25
29
  retry: retry,
26
- status: status
30
+ status: status,
31
+ onClick: onClick
27
32
  }), children));
28
33
  };
29
34
 
@@ -0,0 +1 @@
1
+ export { useSmartLinkActions } from './state/hooks-external/useSmartLinkActions';
@@ -10,8 +10,8 @@ export var useSmartLinkAnalytics = function useSmartLinkAnalytics(dispatchAnalyt
10
10
  authAlternateAccountEvent: function authAlternateAccountEvent(display, definitionId, extensionKey) {
11
11
  return dispatchAnalytics(uiAuthAlternateAccountEvent(display, definitionId, extensionKey));
12
12
  },
13
- cardClickedEvent: function cardClickedEvent(display, definitionId, extensionKey) {
14
- return dispatchAnalytics(uiCardClickedEvent(display, definitionId, extensionKey));
13
+ cardClickedEvent: function cardClickedEvent(display, definitionId, extensionKey, isModifierKeyPressed) {
14
+ return dispatchAnalytics(uiCardClickedEvent(display, definitionId, extensionKey, isModifierKeyPressed));
15
15
  },
16
16
  actionClickedEvent: function actionClickedEvent(id, extensionKey, actionType, display, invokeType) {
17
17
  startUfoExperience('smart-link-action-invocation', id, {
@@ -0,0 +1,54 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import { useEffect, useMemo, useState } from 'react';
3
+ import uuid from 'uuid';
4
+ import { extractBlockProps as extractCardProps } from '../../extractors/block';
5
+ import { useSmartCardActions as useLinkActions } from '../actions';
6
+ import { useSmartLinkAnalytics as useLinkAnalytics } from '../analytics';
7
+ import { useSmartCardState as useLinkState } from '../store';
8
+ import { getExtensionKey } from '../helpers';
9
+ export function useSmartLinkActions(_ref) {
10
+ var url = _ref.url,
11
+ appearance = _ref.appearance,
12
+ analyticsHandler = _ref.analyticsHandler,
13
+ _ref$platform = _ref.platform,
14
+ platform = _ref$platform === void 0 ? 'web' : _ref$platform;
15
+ var id = useMemo(function () {
16
+ return uuid();
17
+ }, []);
18
+
19
+ var _useState = useState([]),
20
+ _useState2 = _slicedToArray(_useState, 2),
21
+ actions = _useState2[0],
22
+ setActions = _useState2[1];
23
+
24
+ var linkState = useLinkState(url);
25
+ var linkAnalytics = useLinkAnalytics(analyticsHandler);
26
+ var linkActions = useLinkActions(id, url, linkAnalytics);
27
+ useEffect(function () {
28
+ if (!linkState.details) {
29
+ return;
30
+ }
31
+
32
+ var cardProperties = extractCardProps(linkState.details.data, linkState.details.meta, {
33
+ handleInvoke: function handleInvoke(opts) {
34
+ return linkActions.invoke(opts, appearance);
35
+ },
36
+ handleAnalytics: analyticsHandler,
37
+ extensionKey: getExtensionKey(linkState.details)
38
+ }, undefined, platform);
39
+
40
+ if (!cardProperties.actions || cardProperties.actions.length === 0) {
41
+ return;
42
+ }
43
+
44
+ var cardActions = cardProperties.actions.map(function (action) {
45
+ return {
46
+ id: action.id,
47
+ text: action.text,
48
+ invoke: action.promise
49
+ };
50
+ });
51
+ setActions(cardActions);
52
+ }, [linkState, linkActions, analyticsHandler, appearance, platform]);
53
+ return actions;
54
+ }
@@ -182,7 +182,7 @@ export var uiAuthAlternateAccountEvent = function uiAuthAlternateAccountEvent(di
182
182
  })
183
183
  };
184
184
  };
185
- export var uiCardClickedEvent = function uiCardClickedEvent(display, definitionId, extensionKey) {
185
+ export var uiCardClickedEvent = function uiCardClickedEvent(display, definitionId, extensionKey, isModifierKeyPressed) {
186
186
  return {
187
187
  action: 'clicked',
188
188
  actionSubject: 'smartLink',
@@ -190,7 +190,8 @@ export var uiCardClickedEvent = function uiCardClickedEvent(display, definitionI
190
190
  attributes: _objectSpread(_objectSpread({}, context), {}, {
191
191
  definitionId: definitionId || '',
192
192
  extensionKey: extensionKey || '',
193
- display: display
193
+ display: display,
194
+ isModifierKeyPressed: isModifierKeyPressed
194
195
  })
195
196
  };
196
197
  };
@@ -11,6 +11,11 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
11
11
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
12
12
 
13
13
  import CardClient from '../client';
14
+ export var mockContext = {
15
+ '@vocab': 'https://www.w3.org/ns/activitystreams#',
16
+ atlassian: 'https://schema.atlassian.com/ns/vocabulary#',
17
+ schema: 'http://schema.org/'
18
+ };
14
19
  export var mocks = {
15
20
  success: {
16
21
  meta: {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "17.7.6",
3
+ "version": "17.7.9",
4
4
  "sideEffects": false
5
5
  }
@@ -26,7 +26,7 @@ export var BlockCard = function BlockCard(_ref) {
26
26
  handleAuthorize = _ref.handleAuthorize,
27
27
  handleErrorRetry = _ref.handleErrorRetry,
28
28
  handleFrameClick = _ref.handleFrameClick,
29
- handlePreviewAnalytics = _ref.handlePreviewAnalytics,
29
+ handleAnalytics = _ref.handleAnalytics,
30
30
  handleInvoke = _ref.handleInvoke,
31
31
  renderers = _ref.renderers,
32
32
  isSelected = _ref.isSelected,
@@ -37,7 +37,7 @@ export var BlockCard = function BlockCard(_ref) {
37
37
  var data = details && details.data || getEmptyJsonLd();
38
38
  var meta = details && details.meta;
39
39
  var extractorOpts = {
40
- handleAnalytics: handlePreviewAnalytics,
40
+ handleAnalytics: handleAnalytics,
41
41
  handleInvoke: handleInvoke,
42
42
  extensionKey: getExtensionKey(details)
43
43
  };
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useCallback } from 'react';
1
+ import React, { useEffect, useCallback, useMemo } from 'react';
2
2
  import { isSpecialEvent } from '../../utils';
3
3
  import * as measure from '../../utils/performance';
4
4
  import { getDefinitionId, getServices, isFinalState, getClickUrl, getResourceType, getExtensionKey } from '../../state/helpers';
@@ -38,7 +38,10 @@ export function CardWithUrlContent(_ref) {
38
38
  var definitionId = getDefinitionId(state.details);
39
39
  var extensionKey = getExtensionKey(state.details);
40
40
  var resourceType = getResourceType(state.details);
41
- var services = getServices(state.details); // Setup UI handlers.
41
+ var services = getServices(state.details);
42
+ var isFlexibleUi = useMemo(function () {
43
+ return isFlexibleUiCard(children);
44
+ }, [children]); // Setup UI handlers.
42
45
 
43
46
  var handleClick = useCallback(function (event) {
44
47
  var clickUrl = getClickUrl(url, state.details);
@@ -46,11 +49,12 @@ export function CardWithUrlContent(_ref) {
46
49
  }, [state.details, url]);
47
50
  var handleClickWrapper = useCallback(function (event) {
48
51
  if (state.status === 'resolved') {
49
- analytics.ui.cardClickedEvent(appearance, definitionId, extensionKey);
52
+ var isModifierKeyPressed = isSpecialEvent(event);
53
+ analytics.ui.cardClickedEvent(isFlexibleUi ? 'flexible' : appearance, definitionId, extensionKey, isModifierKeyPressed);
50
54
  }
51
55
 
52
56
  onClick ? onClick(event) : handleClick(event);
53
- }, [state.status, analytics.ui, appearance, definitionId, extensionKey, onClick, handleClick]);
57
+ }, [state.status, analytics.ui, appearance, definitionId, extensionKey, onClick, handleClick, isFlexibleUi]);
54
58
  var handleAuthorize = useCallback(function () {
55
59
  return actions.authorize(appearance);
56
60
  }, [actions, appearance]);
@@ -84,13 +88,15 @@ export function CardWithUrlContent(_ref) {
84
88
  throw error;
85
89
  }
86
90
 
87
- if (isFlexibleUiCard(children)) {
91
+ if (isFlexibleUi) {
88
92
  return /*#__PURE__*/React.createElement(FlexibleCard, {
89
93
  cardState: state,
90
94
  onAuthorize: services.length && handleAuthorize || undefined,
95
+ onClick: handleClickWrapper,
91
96
  renderers: renderers,
92
97
  ui: ui,
93
- url: url
98
+ url: url,
99
+ testId: testId
94
100
  }, children);
95
101
  }
96
102
 
@@ -118,7 +124,7 @@ export function CardWithUrlContent(_ref) {
118
124
  handleErrorRetry: handleRetry,
119
125
  handleInvoke: handleInvoke,
120
126
  handleFrameClick: handleClickWrapper,
121
- handlePreviewAnalytics: dispatchAnalytics,
127
+ handleAnalytics: dispatchAnalytics,
122
128
  isSelected: isSelected,
123
129
  onResolve: onResolve,
124
130
  testId: testId,
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
4
  import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
5
- var _excluded = ["maxLines", "metadata", "position", "subtitle", "actions", "testId", "theme", "text", "showActionOnHover"];
5
+ var _excluded = ["maxLines", "metadata", "position", "subtitle", "actions", "testId", "theme", "onClick", "text", "showActionOnHover"];
6
6
 
7
7
  var _templateObject;
8
8
 
@@ -28,6 +28,7 @@ var TitleBlockResolvedView = function TitleBlockResolvedView(_ref) {
28
28
  actions = _ref$actions === void 0 ? [] : _ref$actions,
29
29
  testId = _ref.testId,
30
30
  theme = _ref.theme,
31
+ onClick = _ref.onClick,
31
32
  text = _ref.text,
32
33
  showActionOnHover = _ref.showActionOnHover,
33
34
  blockProps = _objectWithoutProperties(_ref, _excluded);
@@ -53,7 +54,8 @@ var TitleBlockResolvedView = function TitleBlockResolvedView(_ref) {
53
54
  width: SmartLinkWidth.Flexible
54
55
  }, jsx(Title, _extends({
55
56
  maxLines: maxLines,
56
- theme: theme
57
+ theme: theme,
58
+ onClick: onClick
57
59
  }, overrideText)), subtitleElements && jsx(ElementGroup, {
58
60
  direction: SmartLinkDirection.Horizontal
59
61
  }, subtitleElements)), metadataElements && jsx(ElementGroup, {
@@ -48,11 +48,12 @@ export var getContainerStyles = function getContainerStyles(size, hideBackground
48
48
  return css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: flex;\n gap: ", " 0;\n flex-direction: column;\n min-width: 0;\n overflow: hidden;\n ", "\n ", "\n ", "\n"])), getGap(size), hideBackground ? '' : "background-color: ".concat(tokens.background, ";"), hidePadding ? '' : "padding: ".concat(getPadding(size), ";"), hideElevation ? '' : elevationStyles);
49
49
  };
50
50
 
51
- var renderChildren = function renderChildren(children, containerSize, containerTheme, status, retry) {
51
+ var renderChildren = function renderChildren(children, containerSize, containerTheme, status, retry, onClick) {
52
52
  return React.Children.map(children, function (child) {
53
53
  if ( /*#__PURE__*/React.isValidElement(child) && isFlexibleUiBlock(child)) {
54
54
  var blockSize = child.props.size;
55
55
  return /*#__PURE__*/React.cloneElement(child, {
56
+ onClick: onClick,
56
57
  retry: isFlexibleUiTitleBlock(child) ? retry : undefined,
57
58
  size: blockSize || containerSize,
58
59
  status: status,
@@ -77,12 +78,13 @@ var Container = function Container(_ref) {
77
78
  _ref$testId = _ref.testId,
78
79
  testId = _ref$testId === void 0 ? 'smart-links-container' : _ref$testId,
79
80
  _ref$theme = _ref.theme,
80
- theme = _ref$theme === void 0 ? SmartLinkTheme.Link : _ref$theme;
81
+ theme = _ref$theme === void 0 ? SmartLinkTheme.Link : _ref$theme,
82
+ onClick = _ref.onClick;
81
83
  return jsx("div", {
82
84
  css: getContainerStyles(size, hideBackground, hideElevation, hidePadding),
83
85
  "data-smart-link-container": true,
84
86
  "data-testid": testId
85
- }, renderChildren(children, size, theme, status, retry));
87
+ }, renderChildren(children, size, theme, status, retry, onClick));
86
88
  };
87
89
 
88
90
  export default Container;
@@ -52,7 +52,8 @@ var Link = function Link(_ref) {
52
52
  text = _ref.text,
53
53
  _ref$theme = _ref.theme,
54
54
  theme = _ref$theme === void 0 ? SmartLinkTheme.Link : _ref$theme,
55
- url = _ref.url;
55
+ url = _ref.url,
56
+ onClick = _ref.onClick;
56
57
  return jsx("span", {
57
58
  css: containerStyles
58
59
  }, jsx(Tooltip, {
@@ -63,6 +64,7 @@ var Link = function Link(_ref) {
63
64
  css: getAnchorStyles(size, theme, getMaxLines(maxLines)),
64
65
  "data-smart-element-link": true,
65
66
  "data-testid": testId,
67
+ onClick: onClick,
66
68
  href: url
67
69
  }, text)));
68
70
  };
@@ -7,9 +7,17 @@ import React from 'react';
7
7
  import { css, jsx } from '@emotion/core';
8
8
  import ImageIcon from '../../common/image-icon';
9
9
 
10
- var styles = function styles(url) {
11
- return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n justify-content: center;\n width: 100%;\n > img {\n max-width: 100%;\n max-height: 100%;\n }\n"])));
12
- };
10
+ /**
11
+ * Media: Image
12
+ * [aspect-ratio: 16 / 9] The context box is fixed to aspect ratio of 16:9.
13
+ * [object-fit: cover] The replaced content is sized to maintain
14
+ * its aspect ratio while filling the element's entire content box.
15
+ * If the object's aspect ratio does not match the aspect ratio of its box,
16
+ * then the object will be clipped to fit.
17
+ * [object-position] Center alignment of the selected replaced element's
18
+ * contents within the element's box.
19
+ */
20
+ var styles = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n aspect-ratio: 16 / 9;\n display: flex;\n width: 100%;\n\n // fallback\n @supports not (aspect-ratio: auto) {\n padding-top: 56.25%; // 16:9 ratio (9 / 16 = 0.5625)\n height: 0;\n position: relative;\n overflow: hidden;\n }\n\n > img {\n min-height: 100%;\n min-width: 100%;\n max-height: 100%;\n max-width: 100%;\n object-fit: cover;\n object-position: center center;\n\n // fallback\n @supports not (aspect-ratio: auto) {\n position: absolute;\n transform: translate(-50%, -50%);\n left: 50%;\n top: 50%;\n width: auto;\n height: auto;\n }\n }\n"])));
13
21
 
14
22
  var Media = function Media(_ref) {
15
23
  var _ref$testId = _ref.testId,
@@ -22,7 +30,7 @@ var Media = function Media(_ref) {
22
30
  }
23
31
 
24
32
  return jsx("div", {
25
- css: styles(url),
33
+ css: styles,
26
34
  "data-smart-element-media": true,
27
35
  "data-testid": testId
28
36
  }, jsx(ImageIcon, {
@@ -10,7 +10,9 @@ var FlexibleCard = function FlexibleCard(_ref) {
10
10
  onAuthorize = _ref.onAuthorize,
11
11
  renderers = _ref.renderers,
12
12
  ui = _ref.ui,
13
- url = _ref.url;
13
+ url = _ref.url,
14
+ onClick = _ref.onClick,
15
+ testId = _ref.testId;
14
16
  var cardType = cardState.status,
15
17
  details = cardState.details;
16
18
  var status = cardType;
@@ -18,9 +20,12 @@ var FlexibleCard = function FlexibleCard(_ref) {
18
20
  var retry = getRetryOptions(url, status, details, onAuthorize);
19
21
  return /*#__PURE__*/React.createElement(FlexibleUiContext.Provider, {
20
22
  value: context
21
- }, /*#__PURE__*/React.createElement(Container, _extends({}, ui, {
23
+ }, /*#__PURE__*/React.createElement(Container, _extends({
24
+ testId: testId
25
+ }, ui, {
22
26
  retry: retry,
23
- status: status
27
+ status: status,
28
+ onClick: onClick
24
29
  }), children));
25
30
  };
26
31
 
@@ -0,0 +1 @@
1
+ export { useSmartLinkActions } from './state/hooks-external/useSmartLinkActions';
@@ -7,7 +7,7 @@ export declare const useSmartLinkAnalytics: (dispatchAnalytics: AnalyticsHandler
7
7
  ui: {
8
8
  authEvent: (display: CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined) => void;
9
9
  authAlternateAccountEvent: (display: CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined) => void;
10
- cardClickedEvent: (display: CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined) => void;
10
+ cardClickedEvent: (display: CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined, isModifierKeyPressed?: boolean | undefined) => void;
11
11
  actionClickedEvent: (id: string, extensionKey: string, actionType: string, display: CardInnerAppearance, invokeType: InvokeType) => void;
12
12
  closedAuthEvent: (display: CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined) => void;
13
13
  renderSuccessEvent: (display: CardInnerAppearance, id: string, definitionId?: string | undefined, extensionKey?: string | undefined) => void;
@@ -12,7 +12,7 @@ export declare function useSmartLink(id: string, url: string, dispatchAnalytics:
12
12
  ui: {
13
13
  authEvent: (display: import("../../view/Card/types").CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined) => void;
14
14
  authAlternateAccountEvent: (display: import("../../view/Card/types").CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined) => void;
15
- cardClickedEvent: (display: import("../../view/Card/types").CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined) => void;
15
+ cardClickedEvent: (display: import("../../view/Card/types").CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined, isModifierKeyPressed?: boolean | undefined) => void;
16
16
  actionClickedEvent: (id: string, extensionKey: string, actionType: string, display: import("../../view/Card/types").CardInnerAppearance, invokeType: import("../../model/invoke-opts").InvokeType) => void;
17
17
  closedAuthEvent: (display: import("../../view/Card/types").CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined) => void;
18
18
  renderSuccessEvent: (display: import("../../view/Card/types").CardInnerAppearance, id: string, definitionId?: string | undefined, extensionKey?: string | undefined) => void;
@@ -0,0 +1,45 @@
1
+ /// <reference types="react" />
2
+ import { JsonLd } from 'json-ld-types';
3
+ import type { AnalyticsHandler } from '../../utils/types';
4
+ import type { CardAppearance } from '../../view/Card/types';
5
+ export interface LinkAction {
6
+ /**
7
+ * Unique ID for the action.
8
+ * @example `delete-action`
9
+ */
10
+ id: string;
11
+ /**
12
+ * Text to render for the action.
13
+ * @description Use this in tooltips and UI.
14
+ * @example `Delete`.
15
+ */
16
+ text: React.ReactNode;
17
+ /**
18
+ * Promise to invoke on triggering this action.
19
+ * @example Clicking on `Delete` leading to deletion of content.
20
+ */
21
+ invoke: () => Promise<any>;
22
+ }
23
+ export interface UseSmartLinkActionsOpts {
24
+ /**
25
+ * Smart Link URL for which actions will be invoked.
26
+ * @example https://start.atlassian.com
27
+ */
28
+ url: string;
29
+ /**
30
+ * Appearance under which these actions will be invoked.
31
+ * @example `block` for card views.
32
+ */
33
+ appearance: CardAppearance;
34
+ /**
35
+ * Callback for sending analytics events.
36
+ * @description Accepts an analytics payload and fires it to a system.
37
+ */
38
+ analyticsHandler: AnalyticsHandler;
39
+ /**
40
+ * Platform on which actions are being invoked.
41
+ * @default 'web'
42
+ */
43
+ platform?: JsonLd.Primitives.Platforms;
44
+ }
45
+ export declare function useSmartLinkActions({ url, appearance, analyticsHandler, platform, }: UseSmartLinkActionsOpts): LinkAction[];
@@ -22,8 +22,8 @@ export declare const connectFailedEvent: (definitionId?: string | undefined, ext
22
22
  export declare const trackAppAccountConnected: (definitionId?: string | undefined, extensionKey?: string | undefined) => AnalyticsPayload;
23
23
  export declare const uiAuthEvent: (display: CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined) => AnalyticsPayload;
24
24
  export declare const uiAuthAlternateAccountEvent: (display: CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined) => AnalyticsPayload;
25
- export declare const uiCardClickedEvent: (display: CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined) => AnalyticsPayload;
26
- export declare const uiActionClickedEvent: (extensionKey: string, actionType: string, display?: "embed" | "block" | "inline" | "preview" | undefined) => AnalyticsPayload;
25
+ export declare const uiCardClickedEvent: (display: CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined, isModifierKeyPressed?: boolean | undefined) => AnalyticsPayload;
26
+ export declare const uiActionClickedEvent: (extensionKey: string, actionType: string, display?: "embed" | "block" | "inline" | "preview" | "flexible" | undefined) => AnalyticsPayload;
27
27
  export declare const uiClosedAuthEvent: (display: CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined) => AnalyticsPayload;
28
28
  export declare const screenAuthPopupEvent: (definitionId?: string | undefined, extensionKey?: string | undefined) => AnalyticsPayload;
29
29
  export declare const uiRenderSuccessEvent: (display: CardInnerAppearance, definitionId?: string | undefined, extensionKey?: string | undefined) => AnalyticsPayload;
@@ -1,4 +1,9 @@
1
1
  import { JsonLd } from 'json-ld-types';
2
+ export declare const mockContext: {
3
+ readonly '@vocab': "https://www.w3.org/ns/activitystreams#";
4
+ readonly atlassian: "https://schema.atlassian.com/ns/vocabulary#";
5
+ readonly schema: "http://schema.org/";
6
+ };
2
7
  export declare const mocks: {
3
8
  success: JsonLd.Response<JsonLd.Data.BaseData>;
4
9
  notFound: JsonLd.Response<JsonLd.Data.BaseData>;
@@ -10,7 +10,7 @@ export declare type BlockCardProps = {
10
10
  authFlow?: CardAuthFlowOpts['authFlow'];
11
11
  handleAuthorize: (() => void) | undefined;
12
12
  handleErrorRetry: () => void;
13
- handlePreviewAnalytics: AnalyticsHandler;
13
+ handleAnalytics: AnalyticsHandler;
14
14
  handleInvoke: InvokeHandler;
15
15
  handleFrameClick: React.EventHandler<React.MouseEvent | React.KeyboardEvent>;
16
16
  isSelected?: boolean;
@@ -4,7 +4,7 @@ import { JsonLd } from 'json-ld-types';
4
4
  import { FlexibleUiOptions } from '../FlexibleCard/types';
5
5
  import { InlinePreloaderStyle } from '../types';
6
6
  export declare type CardAppearance = 'inline' | 'block' | 'embed';
7
- export declare type CardInnerAppearance = CardAppearance | 'preview';
7
+ export declare type CardInnerAppearance = CardAppearance | 'preview' | 'flexible';
8
8
  export declare type CardPlatform = JsonLd.Primitives.Platforms;
9
9
  export declare type OnResolveCallback = (data: {
10
10
  url?: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { BlockProps, ElementItem, ActionItem } from '../types';
2
3
  import { SmartLinkPosition, SmartLinkTheme } from '../../../../../constants';
3
4
  import { RetryOptions } from '../../../types';
@@ -11,4 +12,5 @@ export declare type TitleBlockProps = BlockProps & {
11
12
  theme?: SmartLinkTheme;
12
13
  text?: string;
13
14
  showActionOnHover?: boolean;
15
+ onClick?: React.EventHandler<React.MouseEvent | React.KeyboardEvent>;
14
16
  };
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { SmartLinkSize, SmartLinkStatus, SmartLinkTheme } from '../../../../constants';
2
3
  import { RetryOptions } from '../../types';
3
4
  export declare type ContainerProps = {
@@ -9,4 +10,5 @@ export declare type ContainerProps = {
9
10
  status?: SmartLinkStatus;
10
11
  testId?: string;
11
12
  theme?: SmartLinkTheme;
13
+ onClick?: React.EventHandler<React.MouseEvent | React.KeyboardEvent>;
12
14
  };
@@ -1,6 +1,8 @@
1
+ /// <reference types="react" />
1
2
  import { ElementProps } from '../types';
2
3
  import { SmartLinkTheme } from '../../../../../constants';
3
4
  export declare type LinkProps = ElementProps & {
5
+ onClick?: React.EventHandler<React.MouseEvent | React.KeyboardEvent>;
4
6
  maxLines?: number;
5
7
  text?: string;
6
8
  theme?: SmartLinkTheme;
@@ -12,6 +12,7 @@ export declare type FlexibleCardProps = {
12
12
  testId?: string;
13
13
  ui?: FlexibleUiOptions;
14
14
  url: string;
15
+ onClick?: React.EventHandler<React.MouseEvent | React.KeyboardEvent>;
15
16
  };
16
17
  export declare type FlexibleUiOptions = {
17
18
  hideElevation?: boolean;
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@atlaskit/smart-card/hooks",
3
+ "main": "../dist/cjs/hooks.js",
4
+ "module": "../dist/esm/hooks.js",
5
+ "module:es2019": "../dist/es2019/hooks.js",
6
+ "types": "../dist/types/hooks.d.ts"
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "17.7.6",
3
+ "version": "17.7.9",
4
4
  "description": "Smart card component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -111,6 +111,7 @@
111
111
  "react-dom": "^16.8.0",
112
112
  "react-intl-next": "npm:react-intl@^5.18.1",
113
113
  "react-test-renderer": "^16.8.0",
114
+ "ts-jest": "24.3.0",
114
115
  "typescript": "3.9.6",
115
116
  "xhr-mock": "^2.4.0"
116
117
  },
@@ -119,6 +120,7 @@
119
120
  "./in-product": "./src/in-product.ts",
120
121
  "./client": "./src/client/index.ts",
121
122
  "./types": "./src/types.ts",
123
+ "./hooks": "./src/hooks.ts",
122
124
  ".": "./src/index.ts"
123
125
  },
124
126
  "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.1"