@atlaskit/smart-card 25.9.0 → 25.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/extractors/flexible/extract-state.js +4 -1
- package/dist/cjs/state/actions/index.js +11 -27
- package/dist/cjs/state/hooks/use-resolve/index.js +12 -21
- package/dist/cjs/version.json +1 -1
- package/dist/cjs/view/CardWithUrl/component.js +3 -12
- package/dist/cjs/view/EmbedModal/components/analytics/index.js +9 -9
- package/dist/cjs/view/EmbedModal/utils.js +111 -0
- package/dist/cjs/view/FlexibleCard/components/actions/action/preview-action/index.js +7 -83
- package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/index.js +24 -18
- package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js +35 -5
- package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.js +6 -4
- package/dist/cjs/view/FlexibleCard/components/elements/link/index.js +3 -1
- package/dist/cjs/view/HoverCard/components/HoverCardComponent.js +4 -11
- package/dist/es2019/extractors/flexible/extract-state.js +4 -1
- package/dist/es2019/state/actions/index.js +12 -32
- package/dist/es2019/state/hooks/use-resolve/index.js +12 -21
- package/dist/es2019/version.json +1 -1
- package/dist/es2019/view/CardWithUrl/component.js +2 -8
- package/dist/es2019/view/EmbedModal/components/analytics/index.js +9 -9
- package/dist/es2019/view/EmbedModal/utils.js +77 -0
- package/dist/es2019/view/FlexibleCard/components/actions/action/preview-action/index.js +7 -56
- package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/index.js +11 -7
- package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js +35 -5
- package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.js +9 -1
- package/dist/es2019/view/FlexibleCard/components/elements/link/index.js +11 -4
- package/dist/es2019/view/HoverCard/components/HoverCardComponent.js +3 -10
- package/dist/esm/extractors/flexible/extract-state.js +4 -1
- package/dist/esm/state/actions/index.js +11 -27
- package/dist/esm/state/hooks/use-resolve/index.js +12 -21
- package/dist/esm/version.json +1 -1
- package/dist/esm/view/CardWithUrl/component.js +2 -10
- package/dist/esm/view/EmbedModal/components/analytics/index.js +9 -9
- package/dist/esm/view/EmbedModal/utils.js +98 -0
- package/dist/esm/view/FlexibleCard/components/actions/action/preview-action/index.js +7 -78
- package/dist/esm/view/FlexibleCard/components/common/lozenge-action/index.js +24 -18
- package/dist/esm/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js +37 -5
- package/dist/esm/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.js +4 -3
- package/dist/esm/view/FlexibleCard/components/elements/link/index.js +3 -1
- package/dist/esm/view/HoverCard/components/HoverCardComponent.js +4 -11
- package/dist/types/state/hooks/use-invoke/types.d.ts +5 -0
- package/dist/types/view/CardWithUrl/component.d.ts +1 -1
- package/dist/types/view/EmbedModal/components/analytics/types.d.ts +1 -1
- package/dist/types/view/EmbedModal/utils.d.ts +10 -0
- package/dist/types/view/FlexibleCard/components/actions/action/preview-action/index.d.ts +1 -2
- package/dist/types/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.d.ts +1 -0
- package/dist/types/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/types.d.ts +18 -0
- package/package.json +1 -2
- package/dist/cjs/utils/analytics/SmartLinkAnalyticsContext.js +0 -47
- package/dist/es2019/utils/analytics/SmartLinkAnalyticsContext.js +0 -35
- package/dist/esm/utils/analytics/SmartLinkAnalyticsContext.js +0 -36
- package/dist/types/utils/analytics/SmartLinkAnalyticsContext.d.ts +0 -9
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import Action from '../index';
|
|
4
|
-
import ReactDOM from 'react-dom';
|
|
5
|
-
import { IntlProvider } from 'react-intl-next';
|
|
6
4
|
import { useFlexibleUiAnalyticsContext } from '../../../../../../state/flexible-ui-context';
|
|
7
5
|
import { useSmartLinkAnalytics } from '../../../../../../state';
|
|
8
|
-
import
|
|
6
|
+
import { openPreviewModal } from '../../../../../EmbedModal/utils';
|
|
9
7
|
const PreviewAction = props => {
|
|
10
8
|
const {
|
|
11
9
|
appearance,
|
|
@@ -22,25 +20,15 @@ const PreviewAction = props => {
|
|
|
22
20
|
} = props;
|
|
23
21
|
const defaultAnalytics = useSmartLinkAnalytics(url, () => {});
|
|
24
22
|
const analytics = useFlexibleUiAnalyticsContext() || defaultAnalytics;
|
|
25
|
-
const EmbedIcon = {
|
|
26
|
-
icon: /*#__PURE__*/React.createElement(Icon, linkIcon),
|
|
27
|
-
isFlexibleUi: true
|
|
28
|
-
};
|
|
29
23
|
if (src && url) {
|
|
30
|
-
const embedModal = () =>
|
|
31
|
-
popupMountPointId: 'twp-editor-preview-iframe',
|
|
32
|
-
showModal: true,
|
|
33
|
-
iframeName: 'twp-editor-preview-iframe',
|
|
34
|
-
onClose: () => {},
|
|
35
|
-
download: downloadUrl,
|
|
36
|
-
icon: EmbedIcon,
|
|
37
|
-
providerName: providerName || 'Preview',
|
|
38
|
-
src,
|
|
24
|
+
const embedModal = () => openPreviewModal({
|
|
39
25
|
title,
|
|
40
|
-
|
|
26
|
+
providerName,
|
|
27
|
+
downloadUrl,
|
|
28
|
+
isSupportTheming,
|
|
41
29
|
analytics,
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
linkIcon,
|
|
31
|
+
src
|
|
44
32
|
});
|
|
45
33
|
const action = {
|
|
46
34
|
...props,
|
|
@@ -60,41 +48,4 @@ const PreviewAction = props => {
|
|
|
60
48
|
return null;
|
|
61
49
|
}
|
|
62
50
|
};
|
|
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
|
-
export async function previewFunction({
|
|
78
|
-
popupMountPointId,
|
|
79
|
-
...rest
|
|
80
|
-
}) {
|
|
81
|
-
let popupMountPoint;
|
|
82
|
-
popupMountPoint = document.getElementById(popupMountPointId);
|
|
83
|
-
if (!popupMountPoint) {
|
|
84
|
-
popupMountPoint = document.createElement('div');
|
|
85
|
-
popupMountPoint.id = popupMountPointId;
|
|
86
|
-
popupMountPoint.setAttribute('data-testid', 'preview-modal');
|
|
87
|
-
document.body.appendChild(popupMountPoint);
|
|
88
|
-
}
|
|
89
|
-
let Modal = await import('../../../../../EmbedModal');
|
|
90
|
-
ReactDOM.render( /*#__PURE__*/React.createElement(IntlProvider, {
|
|
91
|
-
locale: "en"
|
|
92
|
-
}, /*#__PURE__*/React.createElement(Modal.default, _extends({}, rest, {
|
|
93
|
-
onClose: _context => {
|
|
94
|
-
if (popupMountPoint) {
|
|
95
|
-
ReactDOM.unmountComponentAtNode(popupMountPoint);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}))), popupMountPoint);
|
|
99
|
-
}
|
|
100
51
|
export default PreviewAction;
|
|
@@ -24,6 +24,7 @@ const LozengeAction = ({
|
|
|
24
24
|
text,
|
|
25
25
|
zIndex
|
|
26
26
|
}) => {
|
|
27
|
+
var _action$update;
|
|
27
28
|
const [isLoaded, setIsLoaded] = useState(false);
|
|
28
29
|
const [isLoading, setIsLoading] = useState(false);
|
|
29
30
|
const [isOpen, setIsOpen] = useState(false);
|
|
@@ -31,6 +32,11 @@ const LozengeAction = ({
|
|
|
31
32
|
const [errorMessage, setErrorMessage] = useState();
|
|
32
33
|
const invoke = useInvoke();
|
|
33
34
|
const reload = useResolve();
|
|
35
|
+
const {
|
|
36
|
+
url,
|
|
37
|
+
id: linkId,
|
|
38
|
+
previewData
|
|
39
|
+
} = (action === null || action === void 0 ? void 0 : (_action$update = action.update) === null || _action$update === void 0 ? void 0 : _action$update.details) || {};
|
|
34
40
|
const handleOpenChange = useCallback(async args => {
|
|
35
41
|
setIsOpen(args.isOpen);
|
|
36
42
|
if (args.isOpen && !isLoaded && action !== null && action !== void 0 && action.read) {
|
|
@@ -71,10 +77,6 @@ const LozengeAction = ({
|
|
|
71
77
|
setIsLoaded(false);
|
|
72
78
|
setIsOpen(false);
|
|
73
79
|
setItems([]);
|
|
74
|
-
const {
|
|
75
|
-
url,
|
|
76
|
-
id: linkId
|
|
77
|
-
} = updateAction.details || {};
|
|
78
80
|
if (url) {
|
|
79
81
|
await reload(url, true, undefined, linkId);
|
|
80
82
|
}
|
|
@@ -87,12 +89,14 @@ const LozengeAction = ({
|
|
|
87
89
|
setErrorMessage(LozengeActionErrorMessages.updateFailed);
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
|
-
}, [action === null || action === void 0 ? void 0 : action.update, invoke, reload]);
|
|
92
|
+
}, [action === null || action === void 0 ? void 0 : action.update, invoke, linkId, reload, url]);
|
|
91
93
|
const dropdownItemGroup = useMemo(() => {
|
|
92
94
|
if (errorMessage) {
|
|
93
95
|
return jsx(LozengeActionError, {
|
|
94
96
|
errorMessage: errorMessage,
|
|
95
|
-
testId: testId
|
|
97
|
+
testId: testId,
|
|
98
|
+
url: url,
|
|
99
|
+
previewData: previewData
|
|
96
100
|
});
|
|
97
101
|
}
|
|
98
102
|
if (items && items.length > 0) {
|
|
@@ -105,7 +109,7 @@ const LozengeAction = ({
|
|
|
105
109
|
testId: `${testId}-item-${idx}`
|
|
106
110
|
})))));
|
|
107
111
|
}
|
|
108
|
-
}, [errorMessage, handleItemClick, items, testId]);
|
|
112
|
+
}, [errorMessage, handleItemClick, items, previewData, testId, url]);
|
|
109
113
|
return jsx(DropdownMenu, {
|
|
110
114
|
isLoading: isLoading,
|
|
111
115
|
isOpen: isOpen,
|
package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js
CHANGED
|
@@ -1,17 +1,41 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
2
|
import { jsx } from '@emotion/react';
|
|
3
|
-
import { Fragment, useMemo } from 'react';
|
|
3
|
+
import { Fragment, useMemo, useCallback } from 'react';
|
|
4
|
+
import { FormattedMessage } from 'react-intl-next';
|
|
4
5
|
import { DropdownItem, DropdownItemGroup } from '@atlaskit/dropdown-menu';
|
|
5
6
|
import { R50, R500 } from '@atlaskit/theme/colors';
|
|
6
7
|
import ErrorIcon from '@atlaskit/icon/glyph/error';
|
|
7
|
-
import { dropdownItemGroupStyles, contentStyles, textStyles } from './styled';
|
|
8
|
+
import { dropdownItemGroupStyles, contentStyles, linkStyles, textStyles } from './styled';
|
|
8
9
|
import { getFormattedMessage } from '../../../utils';
|
|
10
|
+
import { messages } from '../../../../../../messages';
|
|
11
|
+
import { useFlexibleUiAnalyticsContext } from '../../../../../../state/flexible-ui-context';
|
|
12
|
+
import { openPreviewModal } from '../../../../../EmbedModal/utils';
|
|
13
|
+
import useResolve from '../../../../../../state/hooks/use-resolve';
|
|
9
14
|
const MAX_LINE_NUMBER = 8;
|
|
10
15
|
const LozengeActionError = ({
|
|
11
16
|
errorMessage,
|
|
12
17
|
testId,
|
|
13
|
-
maxLineNumber = MAX_LINE_NUMBER
|
|
18
|
+
maxLineNumber = MAX_LINE_NUMBER,
|
|
19
|
+
url,
|
|
20
|
+
previewData
|
|
14
21
|
}) => {
|
|
22
|
+
const reload = useResolve();
|
|
23
|
+
const analytics = useFlexibleUiAnalyticsContext();
|
|
24
|
+
const isPreviewAvailable = previewData && previewData.src !== undefined;
|
|
25
|
+
const handlePreviewClose = useCallback(() => {
|
|
26
|
+
if (url) {
|
|
27
|
+
reload(url, true);
|
|
28
|
+
}
|
|
29
|
+
}, [reload, url]);
|
|
30
|
+
const handlePreviewOpen = useCallback(() => {
|
|
31
|
+
if (isPreviewAvailable) {
|
|
32
|
+
return openPreviewModal({
|
|
33
|
+
...previewData,
|
|
34
|
+
analytics,
|
|
35
|
+
onClose: handlePreviewClose
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}, [analytics, handlePreviewClose, isPreviewAvailable, previewData]);
|
|
15
39
|
const content = useMemo(() => {
|
|
16
40
|
return jsx(Fragment, null, jsx("div", {
|
|
17
41
|
css: contentStyles
|
|
@@ -24,8 +48,14 @@ const LozengeActionError = ({
|
|
|
24
48
|
}), jsx("span", {
|
|
25
49
|
css: textStyles(maxLineNumber),
|
|
26
50
|
"data-testid": `${testId}-error-message`
|
|
27
|
-
}, typeof errorMessage === 'string' ? errorMessage : getFormattedMessage(errorMessage)))
|
|
28
|
-
|
|
51
|
+
}, typeof errorMessage === 'string' ? errorMessage : getFormattedMessage(errorMessage))), isPreviewAvailable ? jsx("div", {
|
|
52
|
+
css: linkStyles
|
|
53
|
+
}, jsx("a", {
|
|
54
|
+
target: "_blank",
|
|
55
|
+
"data-testid": `${testId}-open-embed`,
|
|
56
|
+
onClick: handlePreviewOpen
|
|
57
|
+
}, jsx(FormattedMessage, messages.open_issue_in_jira))) : null);
|
|
58
|
+
}, [errorMessage, handlePreviewOpen, isPreviewAvailable, maxLineNumber, testId]);
|
|
29
59
|
return jsx("span", {
|
|
30
60
|
css: dropdownItemGroupStyles,
|
|
31
61
|
"data-testid": `${testId}-error-item-group`
|
|
@@ -23,7 +23,7 @@ const sharedBlockStyles = css`
|
|
|
23
23
|
export const contentStyles = css`
|
|
24
24
|
${sharedBlockStyles};
|
|
25
25
|
|
|
26
|
-
margin-top: 2px;
|
|
26
|
+
margin-top: ${"var(--ds-space-025, 2px)"};
|
|
27
27
|
align-items: flex-start;
|
|
28
28
|
|
|
29
29
|
> span,
|
|
@@ -34,6 +34,14 @@ export const contentStyles = css`
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
`;
|
|
37
|
+
export const linkStyles = css`
|
|
38
|
+
${sharedBlockStyles};
|
|
39
|
+
|
|
40
|
+
font-size: 0.875rem;
|
|
41
|
+
margin-top: 10px;
|
|
42
|
+
margin-left: ${"var(--ds-space-400, 32px)"};
|
|
43
|
+
margin-bottom: ${"var(--ds-space-025, 2px)"};
|
|
44
|
+
`;
|
|
37
45
|
export const textStyles = maxLines => css`
|
|
38
46
|
line-height: 1rem;
|
|
39
47
|
white-space: normal;
|
|
@@ -15,13 +15,20 @@ const containerStyles = css`
|
|
|
15
15
|
const getThemeStyles = theme => {
|
|
16
16
|
switch (theme) {
|
|
17
17
|
case SmartLinkInternalTheme.Grey:
|
|
18
|
+
// We are being specifc with the CSS selectors to ensure that Confluence overrides
|
|
19
|
+
// do not affect our internal Smart Card styles
|
|
18
20
|
return css`
|
|
19
|
-
|
|
20
|
-
:hover {
|
|
21
|
+
a& {
|
|
21
22
|
color: ${"var(--ds-text-subtlest, #626F86)"};
|
|
22
|
-
|
|
23
|
+
&:active,
|
|
24
|
+
&:visited,
|
|
25
|
+
&:focus,
|
|
26
|
+
&:hover {
|
|
27
|
+
color: ${"var(--ds-text-subtlest, #626F86)"};
|
|
28
|
+
text-decoration: underline;
|
|
29
|
+
}
|
|
30
|
+
font-size: 12px;
|
|
23
31
|
}
|
|
24
|
-
font-size: 12px;
|
|
25
32
|
`;
|
|
26
33
|
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage
|
|
27
34
|
case SmartLinkTheme.Black:
|
|
@@ -9,11 +9,9 @@ import { useSmartCardState as useLinkState } from '../../../state/store';
|
|
|
9
9
|
import HoverCardContent from '../components/HoverCardContent';
|
|
10
10
|
import { CARD_GAP_PX, HOVER_CARD_Z_INDEX } from '../styled';
|
|
11
11
|
import { CardDisplay } from '../../../constants';
|
|
12
|
-
import { SmartLinkAnalyticsContext } from '../../../utils/analytics/SmartLinkAnalyticsContext';
|
|
13
12
|
export const HoverCardComponent = ({
|
|
14
13
|
children,
|
|
15
14
|
url,
|
|
16
|
-
id,
|
|
17
15
|
analyticsHandler,
|
|
18
16
|
analytics,
|
|
19
17
|
canOpen = true,
|
|
@@ -114,11 +112,7 @@ export const HoverCardComponent = ({
|
|
|
114
112
|
}, [closeOnChildClick, hideCard]);
|
|
115
113
|
const content = useCallback(({
|
|
116
114
|
update
|
|
117
|
-
}) => jsx(
|
|
118
|
-
url: url,
|
|
119
|
-
appearance: CardDisplay.HoverCardPreview,
|
|
120
|
-
id: id
|
|
121
|
-
}, jsx(HoverCardContent, {
|
|
115
|
+
}) => jsx(HoverCardContent, {
|
|
122
116
|
onMouseEnter: initShowCard,
|
|
123
117
|
onMouseLeave: initHideCard,
|
|
124
118
|
analytics: analytics,
|
|
@@ -128,9 +122,8 @@ export const HoverCardComponent = ({
|
|
|
128
122
|
onResolve: update,
|
|
129
123
|
renderers: renderers,
|
|
130
124
|
showServerActions: showServerActions,
|
|
131
|
-
url: url
|
|
132
|
-
|
|
133
|
-
})), [analytics, initHideCard, initShowCard, filteredActions, linkState, onActionClick, renderers, showServerActions, url, id]);
|
|
125
|
+
url: url
|
|
126
|
+
}), [analytics, initHideCard, initShowCard, filteredActions, linkState, onActionClick, renderers, showServerActions, url]);
|
|
134
127
|
const trigger = useCallback(triggerProps => jsx("span", {
|
|
135
128
|
ref: parentSpan
|
|
136
129
|
}, jsx("span", _extends({}, triggerProps, {
|
|
@@ -5,6 +5,7 @@ import { extractLozenge } from '../common/lozenge';
|
|
|
5
5
|
import { getExtensionKey } from '../../state/helpers';
|
|
6
6
|
import extractServerAction from './extract-server-action';
|
|
7
7
|
import { extractLink } from '@atlaskit/linking-common/extractors';
|
|
8
|
+
import { extractPreviewAction } from './actions/extract-preview-action';
|
|
8
9
|
var toInvokeRequest = function toInvokeRequest(extensionKey, resourceIdentifiers, actionType, details) {
|
|
9
10
|
if (!actionType) {
|
|
10
11
|
return;
|
|
@@ -34,9 +35,11 @@ var extractAction = function extractAction(response, id) {
|
|
|
34
35
|
}
|
|
35
36
|
var read = toInvokeRequest(extensionKey, action.resourceIdentifiers, (_action$dataRetrieval = action.dataRetrievalAction) === null || _action$dataRetrieval === void 0 ? void 0 : _action$dataRetrieval.name);
|
|
36
37
|
var url = extractLink(data);
|
|
38
|
+
var previewData = response ? extractPreviewAction(response) : null;
|
|
37
39
|
var details = {
|
|
38
40
|
id: id,
|
|
39
|
-
url: url
|
|
41
|
+
url: url,
|
|
42
|
+
previewData: previewData
|
|
40
43
|
};
|
|
41
44
|
var update = toInvokeRequest(extensionKey, action.resourceIdentifiers, (_action$dataUpdateAct = action.dataUpdateAction) === null || _action$dataUpdateAct === void 0 ? void 0 : _action$dataUpdateAct.name, details);
|
|
42
45
|
return read || update ? {
|
|
@@ -16,20 +16,13 @@ export var useSmartCardActions = function useSmartCardActions(id, url, analytics
|
|
|
16
16
|
connections = _useSmartLinkContext.connections;
|
|
17
17
|
var getState = store.getState,
|
|
18
18
|
dispatch = store.dispatch;
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
metadataStatus = _ref.metadataStatus;
|
|
27
|
-
return {
|
|
28
|
-
details: details,
|
|
29
|
-
status: status,
|
|
30
|
-
metadataStatus: metadataStatus
|
|
31
|
-
};
|
|
32
|
-
}, [getState, url]);
|
|
19
|
+
var _ref = getState()[url] || {
|
|
20
|
+
status: SmartLinkStatus.Pending,
|
|
21
|
+
details: undefined
|
|
22
|
+
},
|
|
23
|
+
details = _ref.details,
|
|
24
|
+
status = _ref.status,
|
|
25
|
+
metadataStatus = _ref.metadataStatus;
|
|
33
26
|
var setMetadataStatus = useCallback(function (metadataStatus) {
|
|
34
27
|
dispatch(cardAction(ACTION_UPDATE_METADATA_STATUS, {
|
|
35
28
|
url: url
|
|
@@ -56,8 +49,6 @@ export var useSmartCardActions = function useSmartCardActions(id, url, analytics
|
|
|
56
49
|
}, _callee);
|
|
57
50
|
})), [id, resolveUrl, url]);
|
|
58
51
|
var register = useCallback(function () {
|
|
59
|
-
var _getSmartLinkState = getSmartLinkState(),
|
|
60
|
-
details = _getSmartLinkState.details;
|
|
61
52
|
if (!details) {
|
|
62
53
|
dispatch(cardAction(ACTION_RESOLVING, {
|
|
63
54
|
url: url
|
|
@@ -65,10 +56,8 @@ export var useSmartCardActions = function useSmartCardActions(id, url, analytics
|
|
|
65
56
|
setMetadataStatus('pending');
|
|
66
57
|
}
|
|
67
58
|
return resolve();
|
|
68
|
-
}, [
|
|
59
|
+
}, [details, resolve, dispatch, url, setMetadataStatus]);
|
|
69
60
|
var reload = useCallback(function () {
|
|
70
|
-
var _getSmartLinkState2 = getSmartLinkState(),
|
|
71
|
-
details = _getSmartLinkState2.details;
|
|
72
61
|
var definitionId = getDefinitionId(details);
|
|
73
62
|
if (definitionId) {
|
|
74
63
|
getByDefinitionId(definitionId, getState()).map(function (url) {
|
|
@@ -77,20 +66,15 @@ export var useSmartCardActions = function useSmartCardActions(id, url, analytics
|
|
|
77
66
|
} else {
|
|
78
67
|
resolve(url, true);
|
|
79
68
|
}
|
|
80
|
-
}, [
|
|
69
|
+
}, [details, url, getState, resolve]);
|
|
81
70
|
var loadMetadata = useCallback(function () {
|
|
82
|
-
var _getSmartLinkState3 = getSmartLinkState(),
|
|
83
|
-
metadataStatus = _getSmartLinkState3.metadataStatus;
|
|
84
71
|
//metadataStatus will be undefined for SSR links only
|
|
85
72
|
if (metadataStatus === undefined) {
|
|
86
73
|
setMetadataStatus('pending');
|
|
87
74
|
return resolve(url, false, true);
|
|
88
75
|
}
|
|
89
|
-
}, [
|
|
76
|
+
}, [metadataStatus, resolve, setMetadataStatus, url]);
|
|
90
77
|
var authorize = useCallback(function (appearance) {
|
|
91
|
-
var _getSmartLinkState4 = getSmartLinkState(),
|
|
92
|
-
details = _getSmartLinkState4.details,
|
|
93
|
-
status = _getSmartLinkState4.status;
|
|
94
78
|
var definitionId = getDefinitionId(details);
|
|
95
79
|
var extensionKey = getExtensionKey(details);
|
|
96
80
|
var services = getServices(details);
|
|
@@ -142,7 +126,7 @@ export var useSmartCardActions = function useSmartCardActions(id, url, analytics
|
|
|
142
126
|
reload();
|
|
143
127
|
});
|
|
144
128
|
}
|
|
145
|
-
}, [
|
|
129
|
+
}, [analytics.ui, analytics.screen, analytics.track, analytics.operational, id, reload, details, status]);
|
|
146
130
|
var invoke = useCallback( /*#__PURE__*/function () {
|
|
147
131
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(opts, appearance) {
|
|
148
132
|
var key, action, source, markName, response;
|
|
@@ -2,7 +2,6 @@ import _typeof from "@babel/runtime/helpers/typeof";
|
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
3
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
4
4
|
import { useCallback } from 'react';
|
|
5
|
-
import { unstable_batchedUpdates } from 'react-dom';
|
|
6
5
|
import { addMetadataToExperience } from '../../analytics';
|
|
7
6
|
import { getStatus } from '../../helpers';
|
|
8
7
|
import { ACTION_ERROR, ACTION_ERROR_FALLBACK, ACTION_RELOADING, ACTION_RESOLVED, ACTION_UPDATE_METADATA_STATUS, APIError, cardAction } from '@atlaskit/linking-common';
|
|
@@ -100,26 +99,18 @@ var useResolve = function useResolve() {
|
|
|
100
99
|
return;
|
|
101
100
|
}
|
|
102
101
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
url: resourceUrl
|
|
116
|
-
}, response));
|
|
117
|
-
} else {
|
|
118
|
-
dispatch(cardAction(ACTION_RESOLVED, {
|
|
119
|
-
url: resourceUrl
|
|
120
|
-
}, response, undefined, undefined, isMetadataRequest));
|
|
121
|
-
}
|
|
122
|
-
});
|
|
102
|
+
//if a link resolves normally, metadata will also always be resolved
|
|
103
|
+
setMetadataStatus(resourceUrl, 'resolved');
|
|
104
|
+
// Dispatch Analytics and resolved card action - including unauthorized states.
|
|
105
|
+
if (isReloading) {
|
|
106
|
+
dispatch(cardAction(ACTION_RELOADING, {
|
|
107
|
+
url: resourceUrl
|
|
108
|
+
}, response));
|
|
109
|
+
} else {
|
|
110
|
+
dispatch(cardAction(ACTION_RESOLVED, {
|
|
111
|
+
url: resourceUrl
|
|
112
|
+
}, response, undefined, undefined, isMetadataRequest));
|
|
113
|
+
}
|
|
123
114
|
}, [dispatch, handleResolvedLinkError, hasAuthFlowSupported, setMetadataStatus]);
|
|
124
115
|
return useCallback( /*#__PURE__*/function () {
|
|
125
116
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
|
package/dist/esm/version.json
CHANGED
|
@@ -12,8 +12,7 @@ import { isFlexibleUiCard } from '../../utils/flexible';
|
|
|
12
12
|
import FlexibleCard from '../FlexibleCard';
|
|
13
13
|
import { CardDisplay } from '../../constants';
|
|
14
14
|
import { fireLinkClickedEvent } from '../../utils/analytics/click';
|
|
15
|
-
|
|
16
|
-
function Component(_ref) {
|
|
15
|
+
export function CardWithUrlContent(_ref) {
|
|
17
16
|
var id = _ref.id,
|
|
18
17
|
url = _ref.url,
|
|
19
18
|
isSelected = _ref.isSelected,
|
|
@@ -258,11 +257,4 @@ function Component(_ref) {
|
|
|
258
257
|
onIframeFocus: onIframeFocus
|
|
259
258
|
});
|
|
260
259
|
}
|
|
261
|
-
}
|
|
262
|
-
export var CardWithUrlContent = function CardWithUrlContent(props) {
|
|
263
|
-
return /*#__PURE__*/React.createElement(SmartLinkAnalyticsContext, {
|
|
264
|
-
url: props.url,
|
|
265
|
-
appearance: props.appearance,
|
|
266
|
-
id: props.id
|
|
267
|
-
}, /*#__PURE__*/React.createElement(Component, props));
|
|
268
|
-
};
|
|
260
|
+
}
|
|
@@ -14,23 +14,23 @@ var withAnalytics = function withAnalytics(Component) {
|
|
|
14
14
|
onResize = props.onResize,
|
|
15
15
|
origin = props.origin;
|
|
16
16
|
var handleOnOpen = useCallback(function (context) {
|
|
17
|
-
analytics.screen.modalViewedEvent({
|
|
17
|
+
analytics === null || analytics === void 0 ? void 0 : analytics.screen.modalViewedEvent({
|
|
18
18
|
name: 'embedPreviewModal',
|
|
19
19
|
attributes: {
|
|
20
20
|
origin: origin,
|
|
21
21
|
size: context.size
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
analytics.ui.renderSuccessEvent({
|
|
24
|
+
analytics === null || analytics === void 0 ? void 0 : analytics.ui.renderSuccessEvent({
|
|
25
25
|
status: 'resolved',
|
|
26
26
|
display: CardDisplay.EmbedPreview
|
|
27
27
|
});
|
|
28
28
|
if (onOpen) {
|
|
29
29
|
onOpen(context);
|
|
30
30
|
}
|
|
31
|
-
}, [analytics.screen, analytics.ui, onOpen, origin]);
|
|
31
|
+
}, [analytics === null || analytics === void 0 ? void 0 : analytics.screen, analytics === null || analytics === void 0 ? void 0 : analytics.ui, onOpen, origin]);
|
|
32
32
|
var handleOnOpenFailed = useCallback(function (error, errorInfo) {
|
|
33
|
-
analytics.ui.renderFailedEvent({
|
|
33
|
+
analytics === null || analytics === void 0 ? void 0 : analytics.ui.renderFailedEvent({
|
|
34
34
|
display: CardDisplay.EmbedPreview,
|
|
35
35
|
error: error,
|
|
36
36
|
errorInfo: errorInfo
|
|
@@ -38,9 +38,9 @@ var withAnalytics = function withAnalytics(Component) {
|
|
|
38
38
|
if (onOpenFailed) {
|
|
39
39
|
onOpenFailed(error, errorInfo);
|
|
40
40
|
}
|
|
41
|
-
}, [analytics.ui, onOpenFailed]);
|
|
41
|
+
}, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onOpenFailed]);
|
|
42
42
|
var handleOnClose = useCallback(function (context) {
|
|
43
|
-
analytics.ui.modalClosedEvent({
|
|
43
|
+
analytics === null || analytics === void 0 ? void 0 : analytics.ui.modalClosedEvent({
|
|
44
44
|
actionSubjectId: 'embedPreview',
|
|
45
45
|
attributes: {
|
|
46
46
|
origin: origin,
|
|
@@ -51,9 +51,9 @@ var withAnalytics = function withAnalytics(Component) {
|
|
|
51
51
|
if (onClose) {
|
|
52
52
|
onClose(context);
|
|
53
53
|
}
|
|
54
|
-
}, [analytics.ui, onClose, origin]);
|
|
54
|
+
}, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onClose, origin]);
|
|
55
55
|
var handleOnResize = useCallback(function (context) {
|
|
56
|
-
analytics.ui.buttonClickedEvent({
|
|
56
|
+
analytics === null || analytics === void 0 ? void 0 : analytics.ui.buttonClickedEvent({
|
|
57
57
|
actionSubjectId: 'embedPreviewResize',
|
|
58
58
|
attributes: {
|
|
59
59
|
newSize: context.size,
|
|
@@ -64,7 +64,7 @@ var withAnalytics = function withAnalytics(Component) {
|
|
|
64
64
|
if (onResize) {
|
|
65
65
|
onResize(context);
|
|
66
66
|
}
|
|
67
|
-
}, [analytics.ui, onResize, origin]);
|
|
67
|
+
}, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onResize, origin]);
|
|
68
68
|
return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
|
|
69
69
|
onClose: handleOnClose,
|
|
70
70
|
onOpen: handleOnOpen,
|