@atlaskit/smart-card 25.9.1 → 25.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/extractors/flexible/extract-state.js +4 -1
  3. package/dist/cjs/version.json +1 -1
  4. package/dist/cjs/view/EmbedModal/components/analytics/index.js +9 -9
  5. package/dist/cjs/view/EmbedModal/utils.js +111 -0
  6. package/dist/cjs/view/FlexibleCard/components/actions/action/preview-action/index.js +7 -83
  7. package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/index.js +24 -18
  8. package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js +35 -5
  9. package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.js +6 -4
  10. package/dist/es2019/extractors/flexible/extract-state.js +4 -1
  11. package/dist/es2019/version.json +1 -1
  12. package/dist/es2019/view/EmbedModal/components/analytics/index.js +9 -9
  13. package/dist/es2019/view/EmbedModal/utils.js +77 -0
  14. package/dist/es2019/view/FlexibleCard/components/actions/action/preview-action/index.js +7 -56
  15. package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/index.js +11 -7
  16. package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js +35 -5
  17. package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.js +9 -1
  18. package/dist/esm/extractors/flexible/extract-state.js +4 -1
  19. package/dist/esm/version.json +1 -1
  20. package/dist/esm/view/EmbedModal/components/analytics/index.js +9 -9
  21. package/dist/esm/view/EmbedModal/utils.js +98 -0
  22. package/dist/esm/view/FlexibleCard/components/actions/action/preview-action/index.js +7 -78
  23. package/dist/esm/view/FlexibleCard/components/common/lozenge-action/index.js +24 -18
  24. package/dist/esm/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js +37 -5
  25. package/dist/esm/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.js +4 -3
  26. package/dist/types/state/hooks/use-invoke/types.d.ts +5 -0
  27. package/dist/types/view/EmbedModal/components/analytics/types.d.ts +1 -1
  28. package/dist/types/view/EmbedModal/utils.d.ts +10 -0
  29. package/dist/types/view/FlexibleCard/components/actions/action/preview-action/index.d.ts +1 -2
  30. package/dist/types/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.d.ts +1 -0
  31. package/dist/types/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/types.d.ts +18 -0
  32. package/package.json +1 -1
@@ -13,23 +13,23 @@ const withAnalytics = Component => props => {
13
13
  origin
14
14
  } = props;
15
15
  const handleOnOpen = useCallback(context => {
16
- analytics.screen.modalViewedEvent({
16
+ analytics === null || analytics === void 0 ? void 0 : analytics.screen.modalViewedEvent({
17
17
  name: 'embedPreviewModal',
18
18
  attributes: {
19
19
  origin,
20
20
  size: context.size
21
21
  }
22
22
  });
23
- analytics.ui.renderSuccessEvent({
23
+ analytics === null || analytics === void 0 ? void 0 : analytics.ui.renderSuccessEvent({
24
24
  status: 'resolved',
25
25
  display: CardDisplay.EmbedPreview
26
26
  });
27
27
  if (onOpen) {
28
28
  onOpen(context);
29
29
  }
30
- }, [analytics.screen, analytics.ui, onOpen, origin]);
30
+ }, [analytics === null || analytics === void 0 ? void 0 : analytics.screen, analytics === null || analytics === void 0 ? void 0 : analytics.ui, onOpen, origin]);
31
31
  const handleOnOpenFailed = useCallback((error, errorInfo) => {
32
- analytics.ui.renderFailedEvent({
32
+ analytics === null || analytics === void 0 ? void 0 : analytics.ui.renderFailedEvent({
33
33
  display: CardDisplay.EmbedPreview,
34
34
  error,
35
35
  errorInfo
@@ -37,9 +37,9 @@ const withAnalytics = Component => props => {
37
37
  if (onOpenFailed) {
38
38
  onOpenFailed(error, errorInfo);
39
39
  }
40
- }, [analytics.ui, onOpenFailed]);
40
+ }, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onOpenFailed]);
41
41
  const handleOnClose = useCallback(context => {
42
- analytics.ui.modalClosedEvent({
42
+ analytics === null || analytics === void 0 ? void 0 : analytics.ui.modalClosedEvent({
43
43
  actionSubjectId: 'embedPreview',
44
44
  attributes: {
45
45
  origin,
@@ -50,9 +50,9 @@ const withAnalytics = Component => props => {
50
50
  if (onClose) {
51
51
  onClose(context);
52
52
  }
53
- }, [analytics.ui, onClose, origin]);
53
+ }, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onClose, origin]);
54
54
  const handleOnResize = useCallback(context => {
55
- analytics.ui.buttonClickedEvent({
55
+ analytics === null || analytics === void 0 ? void 0 : analytics.ui.buttonClickedEvent({
56
56
  actionSubjectId: 'embedPreviewResize',
57
57
  attributes: {
58
58
  newSize: context.size,
@@ -63,7 +63,7 @@ const withAnalytics = Component => props => {
63
63
  if (onResize) {
64
64
  onResize(context);
65
65
  }
66
- }, [analytics.ui, onResize, origin]);
66
+ }, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onResize, origin]);
67
67
  return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
68
68
  onClose: handleOnClose,
69
69
  onOpen: handleOnOpen,
@@ -0,0 +1,77 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React from 'react';
3
+ import ReactDOM from 'react-dom';
4
+ import { IntlProvider } from 'react-intl-next';
5
+ import Icon from '../FlexibleCard/components/elements/icon';
6
+ export const openPreviewModal = ({
7
+ analytics,
8
+ downloadUrl: download,
9
+ isSupportTheming,
10
+ linkIcon,
11
+ onClose = () => {},
12
+ providerName,
13
+ src,
14
+ title,
15
+ url
16
+ }) => {
17
+ const EmbedIcon = {
18
+ icon: /*#__PURE__*/React.createElement(Icon, linkIcon),
19
+ isFlexibleUi: true
20
+ };
21
+ return previewFunction({
22
+ popupMountPointId: 'twp-editor-preview-iframe',
23
+ showModal: true,
24
+ iframeName: 'twp-editor-preview-iframe',
25
+ onClose,
26
+ download,
27
+ icon: EmbedIcon,
28
+ providerName: providerName || 'Preview',
29
+ src,
30
+ title,
31
+ url,
32
+ analytics,
33
+ origin: 'smartLinkCard',
34
+ isSupportTheming
35
+ });
36
+ };
37
+
38
+ /*
39
+ Explanatory note:
40
+ Actions don't have access to the react tree of whatever is rendered them
41
+ (and this concept is fraught inside editor anyway) so we want to ensure
42
+ it is mounting to a new unique place. This function manages that, including
43
+ creating an element if it doesn't exist, as well as tidying up the react tree
44
+ (but not the element) upon closing the modal.
45
+
46
+ This may strike you as really uncomfortable as you read it, so I wanted to note
47
+ that a) this was discussed and agreed upon, and b) it's definitely odd, and if
48
+ you find an elegant solution around this, you should definitely feel free to
49
+ refactor it.
50
+ */
51
+ export async function previewFunction({
52
+ popupMountPointId,
53
+ onClose: onEmbedClose,
54
+ ...rest
55
+ }) {
56
+ let popupMountPoint;
57
+ popupMountPoint = document.getElementById(popupMountPointId);
58
+ if (!popupMountPoint) {
59
+ popupMountPoint = document.createElement('div');
60
+ popupMountPoint.id = popupMountPointId;
61
+ popupMountPoint.setAttribute('data-testid', 'preview-modal');
62
+ document.body.appendChild(popupMountPoint);
63
+ }
64
+ let Modal = await import('./index');
65
+ ReactDOM.render( /*#__PURE__*/React.createElement(IntlProvider, {
66
+ locale: "en"
67
+ }, /*#__PURE__*/React.createElement(Modal.default, _extends({}, rest, {
68
+ onClose: _context => {
69
+ if (popupMountPoint) {
70
+ ReactDOM.unmountComponentAtNode(popupMountPoint);
71
+ }
72
+ if (onEmbedClose) {
73
+ onEmbedClose(_context);
74
+ }
75
+ }
76
+ }))), popupMountPoint);
77
+ }
@@ -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 Icon from '../../../elements/icon';
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 = () => previewFunction({
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
- url,
26
+ providerName,
27
+ downloadUrl,
28
+ isSupportTheming,
41
29
  analytics,
42
- origin: 'smartLinkCard',
43
- isSupportTheming
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,
@@ -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
- }, [errorMessage, maxLineNumber, testId]);
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;
@@ -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 ? {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "25.9.1",
3
+ "version": "25.9.2",
4
4
  "sideEffects": false
5
5
  }
@@ -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,
@@ -0,0 +1,98 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
2
+ import _extends from "@babel/runtime/helpers/extends";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
5
+ var _excluded = ["popupMountPointId", "onClose"];
6
+ 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; }
7
+ import React from 'react';
8
+ import ReactDOM from 'react-dom';
9
+ import { IntlProvider } from 'react-intl-next';
10
+ import Icon from '../FlexibleCard/components/elements/icon';
11
+ export var openPreviewModal = function openPreviewModal(_ref) {
12
+ var analytics = _ref.analytics,
13
+ download = _ref.downloadUrl,
14
+ isSupportTheming = _ref.isSupportTheming,
15
+ linkIcon = _ref.linkIcon,
16
+ _ref$onClose = _ref.onClose,
17
+ onClose = _ref$onClose === void 0 ? function () {} : _ref$onClose,
18
+ providerName = _ref.providerName,
19
+ src = _ref.src,
20
+ title = _ref.title,
21
+ url = _ref.url;
22
+ var EmbedIcon = {
23
+ icon: /*#__PURE__*/React.createElement(Icon, linkIcon),
24
+ isFlexibleUi: true
25
+ };
26
+ return previewFunction({
27
+ popupMountPointId: 'twp-editor-preview-iframe',
28
+ showModal: true,
29
+ iframeName: 'twp-editor-preview-iframe',
30
+ onClose: onClose,
31
+ download: download,
32
+ icon: EmbedIcon,
33
+ providerName: providerName || 'Preview',
34
+ src: src,
35
+ title: title,
36
+ url: url,
37
+ analytics: analytics,
38
+ origin: 'smartLinkCard',
39
+ isSupportTheming: isSupportTheming
40
+ });
41
+ };
42
+
43
+ /*
44
+ Explanatory note:
45
+ Actions don't have access to the react tree of whatever is rendered them
46
+ (and this concept is fraught inside editor anyway) so we want to ensure
47
+ it is mounting to a new unique place. This function manages that, including
48
+ creating an element if it doesn't exist, as well as tidying up the react tree
49
+ (but not the element) upon closing the modal.
50
+
51
+ This may strike you as really uncomfortable as you read it, so I wanted to note
52
+ that a) this was discussed and agreed upon, and b) it's definitely odd, and if
53
+ you find an elegant solution around this, you should definitely feel free to
54
+ refactor it.
55
+ */
56
+ export function previewFunction(_x) {
57
+ return _previewFunction.apply(this, arguments);
58
+ }
59
+ function _previewFunction() {
60
+ _previewFunction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
61
+ var popupMountPointId, onEmbedClose, rest, popupMountPoint, Modal;
62
+ return _regeneratorRuntime().wrap(function _callee$(_context2) {
63
+ while (1) {
64
+ switch (_context2.prev = _context2.next) {
65
+ case 0:
66
+ popupMountPointId = _ref2.popupMountPointId, onEmbedClose = _ref2.onClose, rest = _objectWithoutProperties(_ref2, _excluded);
67
+ popupMountPoint = document.getElementById(popupMountPointId);
68
+ if (!popupMountPoint) {
69
+ popupMountPoint = document.createElement('div');
70
+ popupMountPoint.id = popupMountPointId;
71
+ popupMountPoint.setAttribute('data-testid', 'preview-modal');
72
+ document.body.appendChild(popupMountPoint);
73
+ }
74
+ _context2.next = 5;
75
+ return import('./index');
76
+ case 5:
77
+ Modal = _context2.sent;
78
+ ReactDOM.render( /*#__PURE__*/React.createElement(IntlProvider, {
79
+ locale: "en"
80
+ }, /*#__PURE__*/React.createElement(Modal.default, _extends({}, rest, {
81
+ onClose: function onClose(_context) {
82
+ if (popupMountPoint) {
83
+ ReactDOM.unmountComponentAtNode(popupMountPoint);
84
+ }
85
+ if (onEmbedClose) {
86
+ onEmbedClose(_context);
87
+ }
88
+ }
89
+ }))), popupMountPoint);
90
+ case 7:
91
+ case "end":
92
+ return _context2.stop();
93
+ }
94
+ }
95
+ }, _callee);
96
+ }));
97
+ return _previewFunction.apply(this, arguments);
98
+ }