@atlaskit/smart-card 26.3.5 → 26.3.7

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 +12 -0
  2. package/dist/cjs/state/analytics/useLinkClicked.js +38 -0
  3. package/dist/cjs/utils/analytics/LinkAnalyticsContext.js +36 -0
  4. package/dist/cjs/utils/analytics/SmartLinkAnalyticsContext.js +18 -28
  5. package/dist/cjs/utils/analytics/click.js +22 -1
  6. package/dist/cjs/version.json +1 -1
  7. package/dist/cjs/view/BlockCard/components/ContentHeader.js +2 -3
  8. package/dist/cjs/view/EmbedCard/components/ExpandedFrame.js +2 -3
  9. package/dist/cjs/view/EmbedModal/components/link-info/link-info-button/index.js +2 -2
  10. package/dist/cjs/view/FlexibleCard/components/blocks/title-block/index.js +2 -2
  11. package/dist/cjs/view/FlexibleCard/components/container/layered-link/index.js +2 -2
  12. package/dist/cjs/view/FlexibleCard/components/elements/link/index.js +2 -2
  13. package/dist/cjs/view/InlineCard/Frame/index.js +2 -3
  14. package/dist/cjs/view/LinkUrl/index.js +10 -15
  15. package/dist/es2019/state/analytics/useLinkClicked.js +25 -0
  16. package/dist/es2019/utils/analytics/LinkAnalyticsContext.js +29 -0
  17. package/dist/es2019/utils/analytics/SmartLinkAnalyticsContext.js +21 -24
  18. package/dist/es2019/utils/analytics/click.js +22 -1
  19. package/dist/es2019/version.json +1 -1
  20. package/dist/es2019/view/BlockCard/components/ContentHeader.js +1 -1
  21. package/dist/es2019/view/EmbedCard/components/ExpandedFrame.js +1 -1
  22. package/dist/es2019/view/EmbedModal/components/link-info/link-info-button/index.js +1 -1
  23. package/dist/es2019/view/FlexibleCard/components/blocks/title-block/index.js +1 -1
  24. package/dist/es2019/view/FlexibleCard/components/container/layered-link/index.js +1 -1
  25. package/dist/es2019/view/FlexibleCard/components/elements/link/index.js +1 -1
  26. package/dist/es2019/view/InlineCard/Frame/index.js +1 -1
  27. package/dist/es2019/view/LinkUrl/index.js +10 -16
  28. package/dist/esm/state/analytics/useLinkClicked.js +29 -0
  29. package/dist/esm/utils/analytics/LinkAnalyticsContext.js +28 -0
  30. package/dist/esm/utils/analytics/SmartLinkAnalyticsContext.js +19 -26
  31. package/dist/esm/utils/analytics/click.js +21 -1
  32. package/dist/esm/version.json +1 -1
  33. package/dist/esm/view/BlockCard/components/ContentHeader.js +1 -1
  34. package/dist/esm/view/EmbedCard/components/ExpandedFrame.js +1 -1
  35. package/dist/esm/view/EmbedModal/components/link-info/link-info-button/index.js +1 -1
  36. package/dist/esm/view/FlexibleCard/components/blocks/title-block/index.js +1 -1
  37. package/dist/esm/view/FlexibleCard/components/container/layered-link/index.js +1 -1
  38. package/dist/esm/view/FlexibleCard/components/elements/link/index.js +1 -1
  39. package/dist/esm/view/InlineCard/Frame/index.js +1 -1
  40. package/dist/esm/view/LinkUrl/index.js +11 -16
  41. package/dist/types/state/analytics/useLinkClicked.d.ts +8 -0
  42. package/dist/types/utils/analytics/LinkAnalyticsContext.d.ts +17 -0
  43. package/dist/types/utils/analytics/SmartLinkAnalyticsContext.d.ts +8 -3
  44. package/dist/types/utils/analytics/click.d.ts +11 -1
  45. package/dist/types-ts4.5/state/analytics/useLinkClicked.d.ts +8 -0
  46. package/dist/types-ts4.5/utils/analytics/LinkAnalyticsContext.d.ts +17 -0
  47. package/dist/types-ts4.5/utils/analytics/SmartLinkAnalyticsContext.d.ts +8 -3
  48. package/dist/types-ts4.5/utils/analytics/click.d.ts +11 -1
  49. package/package.json +5 -5
  50. package/dist/cjs/state/analytics/useMouseDownEvent.js +0 -24
  51. package/dist/es2019/state/analytics/useMouseDownEvent.js +0 -18
  52. package/dist/esm/state/analytics/useMouseDownEvent.js +0 -17
  53. package/dist/types/state/analytics/useMouseDownEvent.d.ts +0 -3
  54. package/dist/types-ts4.5/state/analytics/useMouseDownEvent.d.ts +0 -3
@@ -5,7 +5,7 @@ import Tooltip from '@atlaskit/tooltip';
5
5
  import { SmartLinkInternalTheme, SmartLinkSize, SmartLinkTheme } from '../../../../../constants';
6
6
  import { getLinkLineHeight, getLinkSizeStyles, getTruncateStyles, hasWhiteSpace } from '../../utils';
7
7
  import { tokens } from '../../../../../utils/token';
8
- import useMouseDownEvent from '../../../../../state/analytics/useMouseDownEvent';
8
+ import { useMouseDownEvent } from '../../../../../state/analytics/useLinkClicked';
9
9
  const DEFAULT_MAX_LINES = 2;
10
10
  const MAXIMUM_MAX_LINES = 2;
11
11
  const MINIMUM_MAX_LINES = 1;
@@ -1,7 +1,7 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { useGlobalTheme } from '@atlaskit/theme/components';
3
3
  import { WrapperAnchor, WrapperSpan } from './styled';
4
- import useMouseDownEvent from '../../../state/analytics/useMouseDownEvent';
4
+ import { useMouseDownEvent } from '../../../state/analytics/useLinkClicked';
5
5
  export const Frame = props => {
6
6
  const {
7
7
  isSelected,
@@ -1,22 +1,22 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React from 'react';
3
+ import { withAnalyticsContext } from '@atlaskit/analytics-next';
4
+ import { name as packageName, version as packageVersion } from '../../version.json';
5
+ import { withLinkClickedEvent } from '../../utils/analytics/click';
6
+ import { LinkAnalyticsContext } from '../../utils/analytics/LinkAnalyticsContext';
3
7
  import { useLinkWarningModal } from './LinkWarningModal/hooks/use-link-warning-modal';
4
8
  import LinkWarningModal from './LinkWarningModal';
5
- import { useAnalyticsEvents, withAnalyticsContext } from '@atlaskit/analytics-next';
6
- import { name as packageName, version as packageVersion } from '../../version.json';
7
- import { fireLinkClickedEvent } from '../../utils/analytics/click';
8
- import useMouseDownEvent from '../../state/analytics/useMouseDownEvent';
9
9
  const PACKAGE_DATA = {
10
10
  packageName,
11
11
  packageVersion,
12
12
  componentName: 'linkUrl'
13
13
  };
14
+ const Link = withLinkClickedEvent('a');
14
15
  const LinkUrl = ({
15
16
  href,
16
17
  children,
17
18
  checkSafety = true,
18
19
  onClick,
19
- onMouseDown,
20
20
  testId = 'link-with-safety',
21
21
  ...props
22
22
  }) => {
@@ -24,22 +24,16 @@ const LinkUrl = ({
24
24
  checkLinkSafety,
25
25
  ...linkWarningModalProps
26
26
  } = useLinkWarningModal();
27
- const {
28
- createAnalyticsEvent
29
- } = useAnalyticsEvents();
30
- const handleMouseDown = useMouseDownEvent();
31
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("a", _extends({
27
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(LinkAnalyticsContext, {
28
+ url: href,
29
+ display: "url"
30
+ }, /*#__PURE__*/React.createElement(Link, _extends({
32
31
  "data-testid": testId,
33
32
  href: href,
34
33
  onClick: e => {
35
34
  checkSafety && checkLinkSafety(e, href);
36
35
  onClick && onClick(e);
37
- fireLinkClickedEvent(createAnalyticsEvent)(e);
38
- },
39
- onMouseDown: e => {
40
- onMouseDown && onMouseDown(e);
41
- handleMouseDown(e); // add analytics
42
36
  }
43
- }, props), children), checkSafety && /*#__PURE__*/React.createElement(LinkWarningModal, linkWarningModalProps));
37
+ }, props), children)), checkSafety && /*#__PURE__*/React.createElement(LinkWarningModal, linkWarningModalProps));
44
38
  };
45
39
  export default withAnalyticsContext(PACKAGE_DATA)(LinkUrl);
@@ -0,0 +1,29 @@
1
+ import { useCallback } from 'react';
2
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
3
+ import { fireLinkClickedEvent } from '../../utils/analytics/click';
4
+ export var ClickButton = /*#__PURE__*/function (ClickButton) {
5
+ ClickButton[ClickButton["Left"] = 0] = "Left";
6
+ ClickButton[ClickButton["Middle"] = 1] = "Middle";
7
+ ClickButton[ClickButton["Right"] = 2] = "Right";
8
+ return ClickButton;
9
+ }({});
10
+ export var useLinkClicked = function useLinkClicked(handler, predicate) {
11
+ var _useAnalyticsEvents = useAnalyticsEvents(),
12
+ createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
13
+ return useCallback(function () {
14
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
15
+ args[_key] = arguments[_key];
16
+ }
17
+ var event = args[0];
18
+ handler === null || handler === void 0 ? void 0 : handler.apply(null, args);
19
+ if (!predicate || predicate !== null && predicate !== void 0 && predicate(event)) {
20
+ fireLinkClickedEvent(createAnalyticsEvent)(event);
21
+ }
22
+ }, [handler, predicate, createAnalyticsEvent]);
23
+ };
24
+ var isNotLeftClick = function isNotLeftClick(event) {
25
+ return event.button !== 0;
26
+ };
27
+ export var useMouseDownEvent = function useMouseDownEvent(onMouseDown) {
28
+ return useLinkClicked(onMouseDown, isNotLeftClick);
29
+ };
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { AnalyticsContext } from '@atlaskit/analytics-next';
3
+ import { getUrlAttributes } from '@atlaskit/link-analytics/resolved-attributes';
4
+ /**
5
+ * Provides an analytics context to supply attributes to events based on a URL
6
+ */
7
+ export var LinkAnalyticsContext = function LinkAnalyticsContext(_ref) {
8
+ var _ref$url = _ref.url,
9
+ url = _ref$url === void 0 ? '' : _ref$url,
10
+ display = _ref.display,
11
+ id = _ref.id,
12
+ children = _ref.children,
13
+ source = _ref.source;
14
+ var _getUrlAttributes = getUrlAttributes(url),
15
+ urlHash = _getUrlAttributes.urlHash;
16
+ var displayCategory = display === 'url' ? 'link' : undefined;
17
+ return /*#__PURE__*/React.createElement(AnalyticsContext, {
18
+ data: {
19
+ source: source,
20
+ attributes: {
21
+ displayCategory: displayCategory,
22
+ urlHash: urlHash,
23
+ display: display,
24
+ id: id
25
+ }
26
+ }
27
+ }, children);
28
+ };
@@ -1,38 +1,31 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- 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; }
3
- 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) { _defineProperty(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; }
4
- import React, { useMemo } from 'react';
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React from 'react';
5
3
  import { AnalyticsContext } from '@atlaskit/analytics-next';
6
- import { getResolvedAttributes, getUrlAttributes } from '@atlaskit/link-analytics/resolved-attributes';
4
+ import { getResolvedAttributes } from '@atlaskit/link-analytics/resolved-attributes';
7
5
  import { isFlexibleUiCard } from '../flexible';
8
6
  import { CardDisplay } from '../../constants';
9
7
  import { useSmartCardState as useSmartLinkState } from '../../state/store';
10
- export var SmartLinkAnalyticsContext = function SmartLinkAnalyticsContext(_ref) {
11
- var children = _ref.children,
12
- url = _ref.url,
13
- appearance = _ref.appearance,
14
- id = _ref.id,
15
- source = _ref.source;
8
+ import { LinkAnalyticsContext } from './LinkAnalyticsContext';
9
+ /**
10
+ * Provides an analytics context to supply attributes to events based on a URL
11
+ * and the link state in the store
12
+ */
13
+ export var SmartLinkAnalyticsContext = function SmartLinkAnalyticsContext(props) {
14
+ var children = props.children,
15
+ appearance = props.appearance,
16
+ url = props.url;
16
17
  var _useSmartLinkState = useSmartLinkState(url),
17
18
  details = _useSmartLinkState.details,
18
19
  status = _useSmartLinkState.status;
19
- var resolvedAttributes = getResolvedAttributes({
20
+ var attributes = getResolvedAttributes({
20
21
  url: url
21
22
  }, details, status);
22
- var _getUrlAttributes = getUrlAttributes(url),
23
- urlHash = _getUrlAttributes.urlHash;
24
- var isFlexibleUi = useMemo(function () {
25
- return isFlexibleUiCard(children);
26
- }, [children]);
27
- var display = isFlexibleUi ? CardDisplay.Flexible : appearance;
28
- return /*#__PURE__*/React.createElement(AnalyticsContext, {
23
+ var display = isFlexibleUiCard(children) ? CardDisplay.Flexible : appearance;
24
+ return /*#__PURE__*/React.createElement(LinkAnalyticsContext, _extends({}, props, {
25
+ display: display
26
+ }), /*#__PURE__*/React.createElement(AnalyticsContext, {
29
27
  data: {
30
- source: source,
31
- attributes: _objectSpread(_objectSpread({}, resolvedAttributes), {}, {
32
- urlHash: urlHash,
33
- display: display,
34
- id: id
35
- })
28
+ attributes: attributes
36
29
  }
37
- }, children);
30
+ }, children));
38
31
  };
@@ -1,8 +1,10 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  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; }
3
3
  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) { _defineProperty(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; }
4
+ import React from 'react';
4
5
  import { browser } from '@atlaskit/linking-common/user-agent';
5
6
  import { ANALYTICS_CHANNEL } from './analytics';
7
+ import { useLinkClicked, useMouseDownEvent } from '../../state/analytics/useLinkClicked';
6
8
  export var buttonMap = new Map([[undefined, 'none'], [0, 'left'], [1, 'middle'], [2, 'right']]);
7
9
  export var getKeys = function getKeys(e) {
8
10
  return ['alt', 'ctrl', 'meta', 'shift'].filter(function (key) {
@@ -112,4 +114,22 @@ export var fireLinkClickedEvent = function fireLinkClickedEvent(createAnalyticsE
112
114
  })).fire(ANALYTICS_CHANNEL);
113
115
  }
114
116
  };
115
- };
117
+ };
118
+ var getDisplayName = function getDisplayName(WrappedComponent) {
119
+ if (typeof WrappedComponent === 'string') {
120
+ return WrappedComponent;
121
+ }
122
+ return WrappedComponent.displayName || WrappedComponent.name || 'Component';
123
+ };
124
+ export function withLinkClickedEvent(WrappedComponent) {
125
+ var Component = function Component(props) {
126
+ var onClick = useLinkClicked(props.onClick);
127
+ var onMouseDown = useMouseDownEvent(props.onMouseDown);
128
+ return /*#__PURE__*/React.createElement(WrappedComponent, _objectSpread(_objectSpread({}, props), {}, {
129
+ onClick: onClick,
130
+ onMouseDown: onMouseDown
131
+ }));
132
+ };
133
+ Component.displayName = "withLinkClickedEvent(".concat(getDisplayName(WrappedComponent), ")");
134
+ return Component;
135
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "26.3.5",
3
+ "version": "26.3.7",
4
4
  "sideEffects": false
5
5
  }
@@ -1,6 +1,6 @@
1
1
  /** @jsx jsx */
2
2
  import { jsx } from '@emotion/react';
3
- import useMouseDownEvent from '../../../state/analytics/useMouseDownEvent';
3
+ import { useMouseDownEvent } from '../../../state/analytics/useLinkClicked';
4
4
  export var blockCardContentHeaderClassName = 'block-card-content-header';
5
5
  export var ContentHeader = function ContentHeader(_ref) {
6
6
  var onClick = _ref.onClick,
@@ -1,7 +1,7 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import { className, LinkWrapper, Wrapper, Header, IconWrapper, TextWrapper, Content } from './styled';
3
3
  import { handleClickCommon } from '../../BlockCard/utils/handlers';
4
- import useMouseDownEvent from '../../../state/analytics/useMouseDownEvent';
4
+ import { useMouseDownEvent } from '../../../state/analytics/useLinkClicked';
5
5
  export var ExpandedFrame = function ExpandedFrame(_ref) {
6
6
  var _ref$isPlaceholder = _ref.isPlaceholder,
7
7
  isPlaceholder = _ref$isPlaceholder === void 0 ? false : _ref$isPlaceholder,
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import Tooltip from '@atlaskit/tooltip';
3
3
  import Button from '@atlaskit/button/custom-theme-button';
4
- import useMouseDownEvent from '../../../../../state/analytics/useMouseDownEvent';
4
+ import { useMouseDownEvent } from '../../../../../state/analytics/useLinkClicked';
5
5
  var LinkInfoButton = function LinkInfoButton(_ref) {
6
6
  var content = _ref.content,
7
7
  href = _ref.href,
@@ -6,7 +6,7 @@ var _excluded = ["actions", "anchorTarget", "hideTitleTooltip", "maxLines", "onA
6
6
  var _templateObject, _templateObject2;
7
7
  import React, { useCallback, useState } from 'react';
8
8
  import { css } from '@emotion/react';
9
- import useMouseDownEvent from '../../../../../state/analytics/useMouseDownEvent';
9
+ import { useMouseDownEvent } from '../../../../../state/analytics/useLinkClicked';
10
10
  import { SmartLinkStatus } from '../../../../../constants';
11
11
  import TitleBlockResolvedView from './resolved';
12
12
  import TitleBlockErroredView from './errored';
@@ -3,7 +3,7 @@ var _templateObject;
3
3
  /** @jsx jsx */
4
4
  import React from 'react';
5
5
  import { jsx, css } from '@emotion/react';
6
- import useMouseDownEvent from '../../../../../state/analytics/useMouseDownEvent';
6
+ import { useMouseDownEvent } from '../../../../../state/analytics/useLinkClicked';
7
7
  var styles = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n // Stretch the invisible link over the whole of the post.\n // Hide the link\u2019s text.\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n overflow: hidden;\n text-indent: 100%;\n white-space: nowrap;\n\n // Needs a heightened specificity to trump other anchor.\n // Stack it under all other links in the post text.\n a&.layered-link {\n position: absolute;\n z-index: 0;\n }\n\n // When hovering over the layered link, any hidden action buttons inside\n // the Container should become visible.\n // As actions resides inside blocks and layered link is expected to be\n // on the same level of blocks. That makes the blocks, e.g. TitleBlock,\n // its sibling. Using general sibling combinator here to apply styling to\n // all the siblings of layered link.\n // The general sibling combinator (~) separates two selectors and matches all\n // iterations of the second element, that are following the first element\n // (though not necessarily immediately), and are children of the same parent\n // element.\n &:hover ~ * {\n .actions-button-group {\n opacity: 1;\n }\n }\n"])));
8
8
 
9
9
  /**
@@ -7,7 +7,7 @@ import Tooltip from '@atlaskit/tooltip';
7
7
  import { SmartLinkInternalTheme, SmartLinkSize, SmartLinkTheme } from '../../../../../constants';
8
8
  import { getLinkLineHeight, getLinkSizeStyles, getTruncateStyles, hasWhiteSpace } from '../../utils';
9
9
  import { tokens } from '../../../../../utils/token';
10
- import useMouseDownEvent from '../../../../../state/analytics/useMouseDownEvent';
10
+ import { useMouseDownEvent } from '../../../../../state/analytics/useLinkClicked';
11
11
  var DEFAULT_MAX_LINES = 2;
12
12
  var MAXIMUM_MAX_LINES = 2;
13
13
  var MINIMUM_MAX_LINES = 1;
@@ -1,7 +1,7 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { useGlobalTheme } from '@atlaskit/theme/components';
3
3
  import { WrapperAnchor, WrapperSpan } from './styled';
4
- import useMouseDownEvent from '../../../state/analytics/useMouseDownEvent';
4
+ import { useMouseDownEvent } from '../../../state/analytics/useLinkClicked';
5
5
  export var Frame = function Frame(props) {
6
6
  var isSelected = props.isSelected,
7
7
  children = props.children,
@@ -1,47 +1,42 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["href", "children", "checkSafety", "onClick", "onMouseDown", "testId"],
3
+ var _excluded = ["href", "children", "checkSafety", "onClick", "testId"],
4
4
  _excluded2 = ["checkLinkSafety"];
5
5
  import React from 'react';
6
+ import { withAnalyticsContext } from '@atlaskit/analytics-next';
7
+ import { name as packageName, version as packageVersion } from '../../version.json';
8
+ import { withLinkClickedEvent } from '../../utils/analytics/click';
9
+ import { LinkAnalyticsContext } from '../../utils/analytics/LinkAnalyticsContext';
6
10
  import { useLinkWarningModal } from './LinkWarningModal/hooks/use-link-warning-modal';
7
11
  import LinkWarningModal from './LinkWarningModal';
8
- import { useAnalyticsEvents, withAnalyticsContext } from '@atlaskit/analytics-next';
9
- import { name as packageName, version as packageVersion } from '../../version.json';
10
- import { fireLinkClickedEvent } from '../../utils/analytics/click';
11
- import useMouseDownEvent from '../../state/analytics/useMouseDownEvent';
12
12
  var PACKAGE_DATA = {
13
13
  packageName: packageName,
14
14
  packageVersion: packageVersion,
15
15
  componentName: 'linkUrl'
16
16
  };
17
+ var Link = withLinkClickedEvent('a');
17
18
  var LinkUrl = function LinkUrl(_ref) {
18
19
  var href = _ref.href,
19
20
  children = _ref.children,
20
21
  _ref$checkSafety = _ref.checkSafety,
21
22
  checkSafety = _ref$checkSafety === void 0 ? true : _ref$checkSafety,
22
23
  _onClick = _ref.onClick,
23
- _onMouseDown = _ref.onMouseDown,
24
24
  _ref$testId = _ref.testId,
25
25
  testId = _ref$testId === void 0 ? 'link-with-safety' : _ref$testId,
26
26
  props = _objectWithoutProperties(_ref, _excluded);
27
27
  var _useLinkWarningModal = useLinkWarningModal(),
28
28
  checkLinkSafety = _useLinkWarningModal.checkLinkSafety,
29
29
  linkWarningModalProps = _objectWithoutProperties(_useLinkWarningModal, _excluded2);
30
- var _useAnalyticsEvents = useAnalyticsEvents(),
31
- createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
32
- var handleMouseDown = useMouseDownEvent();
33
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("a", _extends({
30
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(LinkAnalyticsContext, {
31
+ url: href,
32
+ display: "url"
33
+ }, /*#__PURE__*/React.createElement(Link, _extends({
34
34
  "data-testid": testId,
35
35
  href: href,
36
36
  onClick: function onClick(e) {
37
37
  checkSafety && checkLinkSafety(e, href);
38
38
  _onClick && _onClick(e);
39
- fireLinkClickedEvent(createAnalyticsEvent)(e);
40
- },
41
- onMouseDown: function onMouseDown(e) {
42
- _onMouseDown && _onMouseDown(e);
43
- handleMouseDown(e); // add analytics
44
39
  }
45
- }, props), children), checkSafety && /*#__PURE__*/React.createElement(LinkWarningModal, linkWarningModalProps));
40
+ }, props), children)), checkSafety && /*#__PURE__*/React.createElement(LinkWarningModal, linkWarningModalProps));
46
41
  };
47
42
  export default withAnalyticsContext(PACKAGE_DATA)(LinkUrl);
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ export declare enum ClickButton {
3
+ Left = 0,
4
+ Middle = 1,
5
+ Right = 2
6
+ }
7
+ export declare const useLinkClicked: <T extends import("react").MouseEventHandler<Element>>(handler?: T | undefined, predicate?: ((event: React.MouseEvent) => boolean) | undefined) => (...args: Parameters<T>) => void;
8
+ export declare const useMouseDownEvent: <T extends import("react").MouseEventHandler<Element>>(onMouseDown?: T | undefined) => (...args: Parameters<T>) => void;
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ type LinkAnalyticsContextProps = {
3
+ url?: string;
4
+ /**
5
+ * The display mode of the link
6
+ * @example 'url'
7
+ */
8
+ display?: string | undefined;
9
+ id?: string | undefined;
10
+ source?: string;
11
+ children?: React.ReactNode;
12
+ };
13
+ /**
14
+ * Provides an analytics context to supply attributes to events based on a URL
15
+ */
16
+ export declare const LinkAnalyticsContext: ({ url, display, id, children, source, }: LinkAnalyticsContextProps) => JSX.Element;
17
+ export {};
@@ -1,10 +1,15 @@
1
- import { FC } from 'react';
1
+ import React from 'react';
2
2
  import { CardInnerAppearance } from '../../view/Card/types';
3
3
  type SmartLinkAnalyticsContextProps = {
4
4
  url: string;
5
5
  appearance: CardInnerAppearance;
6
- id: string | undefined;
6
+ id?: string | undefined;
7
7
  source?: string;
8
+ children?: React.ReactNode;
8
9
  };
9
- export declare const SmartLinkAnalyticsContext: FC<SmartLinkAnalyticsContextProps>;
10
+ /**
11
+ * Provides an analytics context to supply attributes to events based on a URL
12
+ * and the link state in the store
13
+ */
14
+ export declare const SmartLinkAnalyticsContext: (props: SmartLinkAnalyticsContextProps) => JSX.Element;
10
15
  export {};
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { AnalyticsEventPayload, UIAnalyticsEvent } from '@atlaskit/analytics-next';
3
3
  import { GasPayload } from '@atlaskit/analytics-gas-types';
4
4
  import { ClickOutcome, ClickType, UiLinkClickedEventProps } from './types';
@@ -13,4 +13,14 @@ type DeepPartial<T> = T extends object ? {
13
13
  export declare const fireLinkClickedEvent: (createAnalyticsEvent: (payload: AnalyticsEventPayload) => UIAnalyticsEvent) => (event: React.MouseEvent, overrides?: DeepPartial<Omit<GasPayload, 'attributes'> & {
14
14
  attributes: UiLinkClickedEventProps;
15
15
  }>) => void;
16
+ export declare function withLinkClickedEvent<Component extends React.ElementType<{
17
+ onClick?: React.MouseEventHandler<HTMLAnchorElement>;
18
+ onMouseDown?: React.MouseEventHandler<HTMLAnchorElement>;
19
+ }>>(WrappedComponent: Component): {
20
+ (props: React.ComponentProps<Component>): React.ReactElement<{
21
+ onClick?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
22
+ onMouseDown?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
23
+ }, string | React.JSXElementConstructor<any>>;
24
+ displayName: string;
25
+ };
16
26
  export {};
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ export declare enum ClickButton {
3
+ Left = 0,
4
+ Middle = 1,
5
+ Right = 2
6
+ }
7
+ export declare const useLinkClicked: <T extends import("react").MouseEventHandler<Element>>(handler?: T | undefined, predicate?: ((event: React.MouseEvent) => boolean) | undefined) => (...args: Parameters<T>) => void;
8
+ export declare const useMouseDownEvent: <T extends import("react").MouseEventHandler<Element>>(onMouseDown?: T | undefined) => (...args: Parameters<T>) => void;
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ type LinkAnalyticsContextProps = {
3
+ url?: string;
4
+ /**
5
+ * The display mode of the link
6
+ * @example 'url'
7
+ */
8
+ display?: string | undefined;
9
+ id?: string | undefined;
10
+ source?: string;
11
+ children?: React.ReactNode;
12
+ };
13
+ /**
14
+ * Provides an analytics context to supply attributes to events based on a URL
15
+ */
16
+ export declare const LinkAnalyticsContext: ({ url, display, id, children, source, }: LinkAnalyticsContextProps) => JSX.Element;
17
+ export {};
@@ -1,10 +1,15 @@
1
- import { FC } from 'react';
1
+ import React from 'react';
2
2
  import { CardInnerAppearance } from '../../view/Card/types';
3
3
  type SmartLinkAnalyticsContextProps = {
4
4
  url: string;
5
5
  appearance: CardInnerAppearance;
6
- id: string | undefined;
6
+ id?: string | undefined;
7
7
  source?: string;
8
+ children?: React.ReactNode;
8
9
  };
9
- export declare const SmartLinkAnalyticsContext: FC<SmartLinkAnalyticsContextProps>;
10
+ /**
11
+ * Provides an analytics context to supply attributes to events based on a URL
12
+ * and the link state in the store
13
+ */
14
+ export declare const SmartLinkAnalyticsContext: (props: SmartLinkAnalyticsContextProps) => JSX.Element;
10
15
  export {};
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { AnalyticsEventPayload, UIAnalyticsEvent } from '@atlaskit/analytics-next';
3
3
  import { GasPayload } from '@atlaskit/analytics-gas-types';
4
4
  import { ClickOutcome, ClickType, UiLinkClickedEventProps } from './types';
@@ -13,4 +13,14 @@ type DeepPartial<T> = T extends object ? {
13
13
  export declare const fireLinkClickedEvent: (createAnalyticsEvent: (payload: AnalyticsEventPayload) => UIAnalyticsEvent) => (event: React.MouseEvent, overrides?: DeepPartial<Omit<GasPayload, 'attributes'> & {
14
14
  attributes: UiLinkClickedEventProps;
15
15
  }>) => void;
16
+ export declare function withLinkClickedEvent<Component extends React.ElementType<{
17
+ onClick?: React.MouseEventHandler<HTMLAnchorElement>;
18
+ onMouseDown?: React.MouseEventHandler<HTMLAnchorElement>;
19
+ }>>(WrappedComponent: Component): {
20
+ (props: React.ComponentProps<Component>): React.ReactElement<{
21
+ onClick?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
22
+ onMouseDown?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
23
+ }, string | React.JSXElementConstructor<any>>;
24
+ displayName: string;
25
+ };
16
26
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "26.3.5",
3
+ "version": "26.3.7",
4
4
  "description": "Smart card component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -47,7 +47,7 @@
47
47
  "@atlaskit/linking-types": "^3.0.0",
48
48
  "@atlaskit/logo": "^13.14.0",
49
49
  "@atlaskit/lozenge": "^11.4.0",
50
- "@atlaskit/media-common": "^4.1.0",
50
+ "@atlaskit/media-common": "^5.0.0",
51
51
  "@atlaskit/modal-dialog": "^12.5.0",
52
52
  "@atlaskit/outbound-auth-flow-client": "^3.4.0",
53
53
  "@atlaskit/platform-feature-flags": "^0.2.1",
@@ -93,11 +93,11 @@
93
93
  "@atlaskit/radio": "^5.6.0",
94
94
  "@atlaskit/range": "^7.1.0",
95
95
  "@atlaskit/section-message": "^6.4.0",
96
- "@atlaskit/select": "^16.3.0",
96
+ "@atlaskit/select": "^16.4.0",
97
97
  "@atlaskit/table-tree": "^9.4.0",
98
98
  "@atlaskit/tabs": "^13.4.0",
99
- "@atlaskit/textarea": "^4.6.0",
100
- "@atlaskit/textfield": "^5.4.0",
99
+ "@atlaskit/textarea": "^4.7.0",
100
+ "@atlaskit/textfield": "^5.5.0",
101
101
  "@atlaskit/toggle": "^12.6.0",
102
102
  "@atlaskit/visual-regression": "*",
103
103
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _react = require("react");
8
- var _analyticsNext = require("@atlaskit/analytics-next");
9
- var _click = require("../../utils/analytics/click");
10
- var useMouseDownEvent = function useMouseDownEvent(onMouseDown) {
11
- var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
12
- createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
13
- return (0, _react.useCallback)(function (event) {
14
- onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(event);
15
-
16
- // ignore left clicks
17
- // these would be handled by `onClick` handler instead
18
- if (event.button !== 0) {
19
- (0, _click.fireLinkClickedEvent)(createAnalyticsEvent)(event);
20
- }
21
- }, [onMouseDown, createAnalyticsEvent]);
22
- };
23
- var _default = useMouseDownEvent;
24
- exports.default = _default;
@@ -1,18 +0,0 @@
1
- import { useCallback } from 'react';
2
- import { useAnalyticsEvents } from '@atlaskit/analytics-next';
3
- import { fireLinkClickedEvent } from '../../utils/analytics/click';
4
- const useMouseDownEvent = onMouseDown => {
5
- const {
6
- createAnalyticsEvent
7
- } = useAnalyticsEvents();
8
- return useCallback(event => {
9
- onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(event);
10
-
11
- // ignore left clicks
12
- // these would be handled by `onClick` handler instead
13
- if (event.button !== 0) {
14
- fireLinkClickedEvent(createAnalyticsEvent)(event);
15
- }
16
- }, [onMouseDown, createAnalyticsEvent]);
17
- };
18
- export default useMouseDownEvent;
@@ -1,17 +0,0 @@
1
- import { useCallback } from 'react';
2
- import { useAnalyticsEvents } from '@atlaskit/analytics-next';
3
- import { fireLinkClickedEvent } from '../../utils/analytics/click';
4
- var useMouseDownEvent = function useMouseDownEvent(onMouseDown) {
5
- var _useAnalyticsEvents = useAnalyticsEvents(),
6
- createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
7
- return useCallback(function (event) {
8
- onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(event);
9
-
10
- // ignore left clicks
11
- // these would be handled by `onClick` handler instead
12
- if (event.button !== 0) {
13
- fireLinkClickedEvent(createAnalyticsEvent)(event);
14
- }
15
- }, [onMouseDown, createAnalyticsEvent]);
16
- };
17
- export default useMouseDownEvent;
@@ -1,3 +0,0 @@
1
- /// <reference types="react" />
2
- declare const useMouseDownEvent: <T extends import("react").MouseEventHandler<Element>>(onMouseDown?: T | undefined) => (event: Parameters<T>[0]) => void;
3
- export default useMouseDownEvent;
@@ -1,3 +0,0 @@
1
- /// <reference types="react" />
2
- declare const useMouseDownEvent: <T extends import("react").MouseEventHandler<Element>>(onMouseDown?: T | undefined) => (event: Parameters<T>[0]) => void;
3
- export default useMouseDownEvent;