@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.
Files changed (52) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/extractors/flexible/extract-state.js +4 -1
  3. package/dist/cjs/state/actions/index.js +11 -27
  4. package/dist/cjs/state/hooks/use-resolve/index.js +12 -21
  5. package/dist/cjs/version.json +1 -1
  6. package/dist/cjs/view/CardWithUrl/component.js +3 -12
  7. package/dist/cjs/view/EmbedModal/components/analytics/index.js +9 -9
  8. package/dist/cjs/view/EmbedModal/utils.js +111 -0
  9. package/dist/cjs/view/FlexibleCard/components/actions/action/preview-action/index.js +7 -83
  10. package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/index.js +24 -18
  11. package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js +35 -5
  12. package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.js +6 -4
  13. package/dist/cjs/view/FlexibleCard/components/elements/link/index.js +3 -1
  14. package/dist/cjs/view/HoverCard/components/HoverCardComponent.js +4 -11
  15. package/dist/es2019/extractors/flexible/extract-state.js +4 -1
  16. package/dist/es2019/state/actions/index.js +12 -32
  17. package/dist/es2019/state/hooks/use-resolve/index.js +12 -21
  18. package/dist/es2019/version.json +1 -1
  19. package/dist/es2019/view/CardWithUrl/component.js +2 -8
  20. package/dist/es2019/view/EmbedModal/components/analytics/index.js +9 -9
  21. package/dist/es2019/view/EmbedModal/utils.js +77 -0
  22. package/dist/es2019/view/FlexibleCard/components/actions/action/preview-action/index.js +7 -56
  23. package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/index.js +11 -7
  24. package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js +35 -5
  25. package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.js +9 -1
  26. package/dist/es2019/view/FlexibleCard/components/elements/link/index.js +11 -4
  27. package/dist/es2019/view/HoverCard/components/HoverCardComponent.js +3 -10
  28. package/dist/esm/extractors/flexible/extract-state.js +4 -1
  29. package/dist/esm/state/actions/index.js +11 -27
  30. package/dist/esm/state/hooks/use-resolve/index.js +12 -21
  31. package/dist/esm/version.json +1 -1
  32. package/dist/esm/view/CardWithUrl/component.js +2 -10
  33. package/dist/esm/view/EmbedModal/components/analytics/index.js +9 -9
  34. package/dist/esm/view/EmbedModal/utils.js +98 -0
  35. package/dist/esm/view/FlexibleCard/components/actions/action/preview-action/index.js +7 -78
  36. package/dist/esm/view/FlexibleCard/components/common/lozenge-action/index.js +24 -18
  37. package/dist/esm/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js +37 -5
  38. package/dist/esm/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.js +4 -3
  39. package/dist/esm/view/FlexibleCard/components/elements/link/index.js +3 -1
  40. package/dist/esm/view/HoverCard/components/HoverCardComponent.js +4 -11
  41. package/dist/types/state/hooks/use-invoke/types.d.ts +5 -0
  42. package/dist/types/view/CardWithUrl/component.d.ts +1 -1
  43. package/dist/types/view/EmbedModal/components/analytics/types.d.ts +1 -1
  44. package/dist/types/view/EmbedModal/utils.d.ts +10 -0
  45. package/dist/types/view/FlexibleCard/components/actions/action/preview-action/index.d.ts +1 -2
  46. package/dist/types/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.d.ts +1 -0
  47. package/dist/types/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/types.d.ts +18 -0
  48. package/package.json +1 -2
  49. package/dist/cjs/utils/analytics/SmartLinkAnalyticsContext.js +0 -47
  50. package/dist/es2019/utils/analytics/SmartLinkAnalyticsContext.js +0 -35
  51. package/dist/esm/utils/analytics/SmartLinkAnalyticsContext.js +0 -36
  52. package/dist/types/utils/analytics/SmartLinkAnalyticsContext.d.ts +0 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/smart-card
2
2
 
3
+ ## 25.9.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`845816bac34`](https://bitbucket.org/atlassian/atlassian-frontend/commits/845816bac34) - [ux] Added a link to open preview modal on action error
8
+
9
+ ## 25.9.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`b76602c1619`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b76602c1619) - Revert 25.8.0 changes "Include additional attributes (urlHash, display, id) and resolved attributes for link clicked analytics events" due to regression
14
+ - [`1aedc244e41`](https://bitbucket.org/atlassian/atlassian-frontend/commits/1aedc244e41) - [ux] Smart Links Internal Grey theme is now more specific to prevent Confluence override
15
+
3
16
  ## 25.9.0
4
17
 
5
18
  ### Minor Changes
@@ -10,6 +10,7 @@ var _lozenge = require("../common/lozenge");
10
10
  var _helpers = require("../../state/helpers");
11
11
  var _extractServerAction = _interopRequireDefault(require("./extract-server-action"));
12
12
  var _extractors = require("@atlaskit/linking-common/extractors");
13
+ var _extractPreviewAction = require("./actions/extract-preview-action");
13
14
  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; }
14
15
  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) { (0, _defineProperty2.default)(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; }
15
16
  var toInvokeRequest = function toInvokeRequest(extensionKey, resourceIdentifiers, actionType, details) {
@@ -41,9 +42,11 @@ var extractAction = function extractAction(response, id) {
41
42
  }
42
43
  var read = toInvokeRequest(extensionKey, action.resourceIdentifiers, (_action$dataRetrieval = action.dataRetrievalAction) === null || _action$dataRetrieval === void 0 ? void 0 : _action$dataRetrieval.name);
43
44
  var url = (0, _extractors.extractLink)(data);
45
+ var previewData = response ? (0, _extractPreviewAction.extractPreviewAction)(response) : null;
44
46
  var details = {
45
47
  id: id,
46
- url: url
48
+ url: url,
49
+ previewData: previewData
47
50
  };
48
51
  var update = toInvokeRequest(extensionKey, action.resourceIdentifiers, (_action$dataUpdateAct = action.dataUpdateAction) === null || _action$dataUpdateAct === void 0 ? void 0 : _action$dataUpdateAct.name, details);
49
52
  return read || update ? {
@@ -25,20 +25,13 @@ var useSmartCardActions = function useSmartCardActions(id, url, analytics) {
25
25
  connections = _useSmartLinkContext.connections;
26
26
  var getState = store.getState,
27
27
  dispatch = store.dispatch;
28
- var getSmartLinkState = (0, _react.useCallback)(function () {
29
- var _getState$url;
30
- var _ref = (_getState$url = getState()[url]) !== null && _getState$url !== void 0 ? _getState$url : {
31
- status: _constants.SmartLinkStatus.Pending
32
- },
33
- details = _ref.details,
34
- status = _ref.status,
35
- metadataStatus = _ref.metadataStatus;
36
- return {
37
- details: details,
38
- status: status,
39
- metadataStatus: metadataStatus
40
- };
41
- }, [getState, url]);
28
+ var _ref = getState()[url] || {
29
+ status: _constants.SmartLinkStatus.Pending,
30
+ details: undefined
31
+ },
32
+ details = _ref.details,
33
+ status = _ref.status,
34
+ metadataStatus = _ref.metadataStatus;
42
35
  var setMetadataStatus = (0, _react.useCallback)(function (metadataStatus) {
43
36
  dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_UPDATE_METADATA_STATUS, {
44
37
  url: url
@@ -65,8 +58,6 @@ var useSmartCardActions = function useSmartCardActions(id, url, analytics) {
65
58
  }, _callee);
66
59
  })), [id, resolveUrl, url]);
67
60
  var register = (0, _react.useCallback)(function () {
68
- var _getSmartLinkState = getSmartLinkState(),
69
- details = _getSmartLinkState.details;
70
61
  if (!details) {
71
62
  dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RESOLVING, {
72
63
  url: url
@@ -74,10 +65,8 @@ var useSmartCardActions = function useSmartCardActions(id, url, analytics) {
74
65
  setMetadataStatus('pending');
75
66
  }
76
67
  return resolve();
77
- }, [getSmartLinkState, resolve, dispatch, url, setMetadataStatus]);
68
+ }, [details, resolve, dispatch, url, setMetadataStatus]);
78
69
  var reload = (0, _react.useCallback)(function () {
79
- var _getSmartLinkState2 = getSmartLinkState(),
80
- details = _getSmartLinkState2.details;
81
70
  var definitionId = (0, _helpers.getDefinitionId)(details);
82
71
  if (definitionId) {
83
72
  (0, _helpers.getByDefinitionId)(definitionId, getState()).map(function (url) {
@@ -86,20 +75,15 @@ var useSmartCardActions = function useSmartCardActions(id, url, analytics) {
86
75
  } else {
87
76
  resolve(url, true);
88
77
  }
89
- }, [getSmartLinkState, url, getState, resolve]);
78
+ }, [details, url, getState, resolve]);
90
79
  var loadMetadata = (0, _react.useCallback)(function () {
91
- var _getSmartLinkState3 = getSmartLinkState(),
92
- metadataStatus = _getSmartLinkState3.metadataStatus;
93
80
  //metadataStatus will be undefined for SSR links only
94
81
  if (metadataStatus === undefined) {
95
82
  setMetadataStatus('pending');
96
83
  return resolve(url, false, true);
97
84
  }
98
- }, [getSmartLinkState, resolve, setMetadataStatus, url]);
85
+ }, [metadataStatus, resolve, setMetadataStatus, url]);
99
86
  var authorize = (0, _react.useCallback)(function (appearance) {
100
- var _getSmartLinkState4 = getSmartLinkState(),
101
- details = _getSmartLinkState4.details,
102
- status = _getSmartLinkState4.status;
103
87
  var definitionId = (0, _helpers.getDefinitionId)(details);
104
88
  var extensionKey = (0, _helpers.getExtensionKey)(details);
105
89
  var services = (0, _helpers.getServices)(details);
@@ -151,7 +135,7 @@ var useSmartCardActions = function useSmartCardActions(id, url, analytics) {
151
135
  reload();
152
136
  });
153
137
  }
154
- }, [getSmartLinkState, analytics.ui, analytics.screen, analytics.track, analytics.operational, id, reload]);
138
+ }, [analytics.ui, analytics.screen, analytics.track, analytics.operational, id, reload, details, status]);
155
139
  var invoke = (0, _react.useCallback)( /*#__PURE__*/function () {
156
140
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(opts, appearance) {
157
141
  var key, action, source, markName, response;
@@ -8,7 +8,6 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.default = void 0;
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
10
  var _react = require("react");
11
- var _reactDom = require("react-dom");
12
11
  var _analytics = require("../../analytics");
13
12
  var _helpers = require("../../helpers");
14
13
  var _linkingCommon = require("@atlaskit/linking-common");
@@ -107,26 +106,18 @@ var useResolve = function useResolve() {
107
106
  return;
108
107
  }
109
108
 
110
- /**
111
- * Using unstable_batchedUpdates because this store update happens async and trigers a rerender
112
- * more info:
113
- * https://github.com/facebook/react/blob/v18.2.0/packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js#L113
114
- * https://react-redux.js.org/api/batch
115
- */
116
- (0, _reactDom.unstable_batchedUpdates)(function () {
117
- //if a link resolves normally, metadata will also always be resolved
118
- setMetadataStatus(resourceUrl, 'resolved');
119
- // Dispatch Analytics and resolved card action - including unauthorized states.
120
- if (isReloading) {
121
- dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RELOADING, {
122
- url: resourceUrl
123
- }, response));
124
- } else {
125
- dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RESOLVED, {
126
- url: resourceUrl
127
- }, response, undefined, undefined, isMetadataRequest));
128
- }
129
- });
109
+ //if a link resolves normally, metadata will also always be resolved
110
+ setMetadataStatus(resourceUrl, 'resolved');
111
+ // Dispatch Analytics and resolved card action - including unauthorized states.
112
+ if (isReloading) {
113
+ dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RELOADING, {
114
+ url: resourceUrl
115
+ }, response));
116
+ } else {
117
+ dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RESOLVED, {
118
+ url: resourceUrl
119
+ }, response, undefined, undefined, isMetadataRequest));
120
+ }
130
121
  }, [dispatch, handleResolvedLinkError, hasAuthFlowSupported, setMetadataStatus]);
131
122
  return (0, _react.useCallback)( /*#__PURE__*/function () {
132
123
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "25.9.0",
3
+ "version": "25.9.2",
4
4
  "sideEffects": false
5
5
  }
@@ -5,7 +5,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.CardWithUrlContent = void 0;
8
+ exports.CardWithUrlContent = CardWithUrlContent;
9
9
  var _react = _interopRequireWildcard(require("react"));
10
10
  var _analyticsNext = require("@atlaskit/analytics-next");
11
11
  var _linkProvider = require("@atlaskit/link-provider");
@@ -20,10 +20,9 @@ var _flexible = require("../../utils/flexible");
20
20
  var _FlexibleCard = _interopRequireDefault(require("../FlexibleCard"));
21
21
  var _constants = require("../../constants");
22
22
  var _click = require("../../utils/analytics/click");
23
- var _SmartLinkAnalyticsContext = require("../../utils/analytics/SmartLinkAnalyticsContext");
24
23
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
24
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
26
- function Component(_ref) {
25
+ function CardWithUrlContent(_ref) {
27
26
  var id = _ref.id,
28
27
  url = _ref.url,
29
28
  isSelected = _ref.isSelected,
@@ -268,12 +267,4 @@ function Component(_ref) {
268
267
  onIframeFocus: onIframeFocus
269
268
  });
270
269
  }
271
- }
272
- var CardWithUrlContent = function CardWithUrlContent(props) {
273
- return /*#__PURE__*/_react.default.createElement(_SmartLinkAnalyticsContext.SmartLinkAnalyticsContext, {
274
- url: props.url,
275
- appearance: props.appearance,
276
- id: props.id
277
- }, /*#__PURE__*/_react.default.createElement(Component, props));
278
- };
279
- exports.CardWithUrlContent = CardWithUrlContent;
270
+ }
@@ -24,23 +24,23 @@ var withAnalytics = function withAnalytics(Component) {
24
24
  onResize = props.onResize,
25
25
  origin = props.origin;
26
26
  var handleOnOpen = (0, _react.useCallback)(function (context) {
27
- analytics.screen.modalViewedEvent({
27
+ analytics === null || analytics === void 0 ? void 0 : analytics.screen.modalViewedEvent({
28
28
  name: 'embedPreviewModal',
29
29
  attributes: {
30
30
  origin: origin,
31
31
  size: context.size
32
32
  }
33
33
  });
34
- analytics.ui.renderSuccessEvent({
34
+ analytics === null || analytics === void 0 ? void 0 : analytics.ui.renderSuccessEvent({
35
35
  status: 'resolved',
36
36
  display: _constants.CardDisplay.EmbedPreview
37
37
  });
38
38
  if (onOpen) {
39
39
  onOpen(context);
40
40
  }
41
- }, [analytics.screen, analytics.ui, onOpen, origin]);
41
+ }, [analytics === null || analytics === void 0 ? void 0 : analytics.screen, analytics === null || analytics === void 0 ? void 0 : analytics.ui, onOpen, origin]);
42
42
  var handleOnOpenFailed = (0, _react.useCallback)(function (error, errorInfo) {
43
- analytics.ui.renderFailedEvent({
43
+ analytics === null || analytics === void 0 ? void 0 : analytics.ui.renderFailedEvent({
44
44
  display: _constants.CardDisplay.EmbedPreview,
45
45
  error: error,
46
46
  errorInfo: errorInfo
@@ -48,9 +48,9 @@ var withAnalytics = function withAnalytics(Component) {
48
48
  if (onOpenFailed) {
49
49
  onOpenFailed(error, errorInfo);
50
50
  }
51
- }, [analytics.ui, onOpenFailed]);
51
+ }, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onOpenFailed]);
52
52
  var handleOnClose = (0, _react.useCallback)(function (context) {
53
- analytics.ui.modalClosedEvent({
53
+ analytics === null || analytics === void 0 ? void 0 : analytics.ui.modalClosedEvent({
54
54
  actionSubjectId: 'embedPreview',
55
55
  attributes: {
56
56
  origin: origin,
@@ -61,9 +61,9 @@ var withAnalytics = function withAnalytics(Component) {
61
61
  if (onClose) {
62
62
  onClose(context);
63
63
  }
64
- }, [analytics.ui, onClose, origin]);
64
+ }, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onClose, origin]);
65
65
  var handleOnResize = (0, _react.useCallback)(function (context) {
66
- analytics.ui.buttonClickedEvent({
66
+ analytics === null || analytics === void 0 ? void 0 : analytics.ui.buttonClickedEvent({
67
67
  actionSubjectId: 'embedPreviewResize',
68
68
  attributes: {
69
69
  newSize: context.size,
@@ -74,7 +74,7 @@ var withAnalytics = function withAnalytics(Component) {
74
74
  if (onResize) {
75
75
  onResize(context);
76
76
  }
77
- }, [analytics.ui, onResize, origin]);
77
+ }, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onResize, origin]);
78
78
  return /*#__PURE__*/_react.default.createElement(Component, (0, _extends2.default)({}, props, {
79
79
  onClose: handleOnClose,
80
80
  onOpen: handleOnOpen,
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.openPreviewModal = void 0;
9
+ exports.previewFunction = previewFunction;
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+ var _react = _interopRequireDefault(require("react"));
14
+ var _reactDom = _interopRequireDefault(require("react-dom"));
15
+ var _reactIntlNext = require("react-intl-next");
16
+ var _icon = _interopRequireDefault(require("../FlexibleCard/components/elements/icon"));
17
+ var _excluded = ["popupMountPointId", "onClose"];
18
+ 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; }
19
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
20
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
+ var openPreviewModal = function openPreviewModal(_ref) {
22
+ var analytics = _ref.analytics,
23
+ download = _ref.downloadUrl,
24
+ isSupportTheming = _ref.isSupportTheming,
25
+ linkIcon = _ref.linkIcon,
26
+ _ref$onClose = _ref.onClose,
27
+ onClose = _ref$onClose === void 0 ? function () {} : _ref$onClose,
28
+ providerName = _ref.providerName,
29
+ src = _ref.src,
30
+ title = _ref.title,
31
+ url = _ref.url;
32
+ var EmbedIcon = {
33
+ icon: /*#__PURE__*/_react.default.createElement(_icon.default, linkIcon),
34
+ isFlexibleUi: true
35
+ };
36
+ return previewFunction({
37
+ popupMountPointId: 'twp-editor-preview-iframe',
38
+ showModal: true,
39
+ iframeName: 'twp-editor-preview-iframe',
40
+ onClose: onClose,
41
+ download: download,
42
+ icon: EmbedIcon,
43
+ providerName: providerName || 'Preview',
44
+ src: src,
45
+ title: title,
46
+ url: url,
47
+ analytics: analytics,
48
+ origin: 'smartLinkCard',
49
+ isSupportTheming: isSupportTheming
50
+ });
51
+ };
52
+
53
+ /*
54
+ Explanatory note:
55
+ Actions don't have access to the react tree of whatever is rendered them
56
+ (and this concept is fraught inside editor anyway) so we want to ensure
57
+ it is mounting to a new unique place. This function manages that, including
58
+ creating an element if it doesn't exist, as well as tidying up the react tree
59
+ (but not the element) upon closing the modal.
60
+
61
+ This may strike you as really uncomfortable as you read it, so I wanted to note
62
+ that a) this was discussed and agreed upon, and b) it's definitely odd, and if
63
+ you find an elegant solution around this, you should definitely feel free to
64
+ refactor it.
65
+ */
66
+ exports.openPreviewModal = openPreviewModal;
67
+ function previewFunction(_x) {
68
+ return _previewFunction.apply(this, arguments);
69
+ }
70
+ function _previewFunction() {
71
+ _previewFunction = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
72
+ var popupMountPointId, onEmbedClose, rest, popupMountPoint, Modal;
73
+ return _regeneratorRuntime().wrap(function _callee$(_context2) {
74
+ while (1) {
75
+ switch (_context2.prev = _context2.next) {
76
+ case 0:
77
+ popupMountPointId = _ref2.popupMountPointId, onEmbedClose = _ref2.onClose, rest = (0, _objectWithoutProperties2.default)(_ref2, _excluded);
78
+ popupMountPoint = document.getElementById(popupMountPointId);
79
+ if (!popupMountPoint) {
80
+ popupMountPoint = document.createElement('div');
81
+ popupMountPoint.id = popupMountPointId;
82
+ popupMountPoint.setAttribute('data-testid', 'preview-modal');
83
+ document.body.appendChild(popupMountPoint);
84
+ }
85
+ _context2.next = 5;
86
+ return Promise.resolve().then(function () {
87
+ return _interopRequireWildcard(require('./index'));
88
+ });
89
+ case 5:
90
+ Modal = _context2.sent;
91
+ _reactDom.default.render( /*#__PURE__*/_react.default.createElement(_reactIntlNext.IntlProvider, {
92
+ locale: "en"
93
+ }, /*#__PURE__*/_react.default.createElement(Modal.default, (0, _extends2.default)({}, rest, {
94
+ onClose: function onClose(_context) {
95
+ if (popupMountPoint) {
96
+ _reactDom.default.unmountComponentAtNode(popupMountPoint);
97
+ }
98
+ if (onEmbedClose) {
99
+ onEmbedClose(_context);
100
+ }
101
+ }
102
+ }))), popupMountPoint);
103
+ case 7:
104
+ case "end":
105
+ return _context2.stop();
106
+ }
107
+ }
108
+ }, _callee);
109
+ }));
110
+ return _previewFunction.apply(this, arguments);
111
+ }
@@ -1,27 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
- exports.previewFunction = previewFunction;
10
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
12
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
10
  var _react = _interopRequireDefault(require("react"));
15
11
  var _index = _interopRequireDefault(require("../index"));
16
- var _reactDom = _interopRequireDefault(require("react-dom"));
17
- var _reactIntlNext = require("react-intl-next");
18
12
  var _flexibleUiContext = require("../../../../../../state/flexible-ui-context");
19
13
  var _state = require("../../../../../../state");
20
- var _icon = _interopRequireDefault(require("../../../elements/icon"));
21
- var _excluded = ["popupMountPointId"];
22
- 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; }
23
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
24
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
+ var _utils = require("../../../../../EmbedModal/utils");
25
15
  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; }
26
16
  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) { (0, _defineProperty2.default)(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; }
27
17
  var PreviewAction = function PreviewAction(props) {
@@ -38,26 +28,16 @@ var PreviewAction = function PreviewAction(props) {
38
28
  isSupportTheming = props.isSupportTheming;
39
29
  var defaultAnalytics = (0, _state.useSmartLinkAnalytics)(url, function () {});
40
30
  var analytics = (0, _flexibleUiContext.useFlexibleUiAnalyticsContext)() || defaultAnalytics;
41
- var EmbedIcon = {
42
- icon: /*#__PURE__*/_react.default.createElement(_icon.default, linkIcon),
43
- isFlexibleUi: true
44
- };
45
31
  if (src && url) {
46
32
  var embedModal = function embedModal() {
47
- return previewFunction({
48
- popupMountPointId: 'twp-editor-preview-iframe',
49
- showModal: true,
50
- iframeName: 'twp-editor-preview-iframe',
51
- onClose: function onClose() {},
52
- download: downloadUrl,
53
- icon: EmbedIcon,
54
- providerName: providerName || 'Preview',
55
- src: src,
33
+ return (0, _utils.openPreviewModal)({
56
34
  title: title,
57
- url: url,
35
+ providerName: providerName,
36
+ downloadUrl: downloadUrl,
37
+ isSupportTheming: isSupportTheming,
58
38
  analytics: analytics,
59
- origin: 'smartLinkCard',
60
- isSupportTheming: isSupportTheming
39
+ linkIcon: linkIcon,
40
+ src: src
61
41
  });
62
42
  };
63
43
  var action = _objectSpread(_objectSpread({}, props), {}, {
@@ -77,61 +57,5 @@ var PreviewAction = function PreviewAction(props) {
77
57
  return null;
78
58
  }
79
59
  };
80
-
81
- /*
82
- Explanatory note:
83
- Actions don't have access to the react tree of whatever is rendered them
84
- (and this concept is fraught inside editor anyway) so we want to ensure
85
- it is mounting to a new unique place. This function manages that, including
86
- creating an element if it doesn't exist, as well as tidying up the react tree
87
- (but not the element) upon closing the modal.
88
-
89
- This may strike you as really uncomfortable as you read it, so I wanted to note
90
- that a) this was discussed and agreed upon, and b) it's definitely odd, and if
91
- you find an elegant solution around this, you should definitely feel free to
92
- refactor it.
93
- */
94
- function previewFunction(_x) {
95
- return _previewFunction.apply(this, arguments);
96
- }
97
- function _previewFunction() {
98
- _previewFunction = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
99
- var popupMountPointId, rest, popupMountPoint, Modal;
100
- return _regeneratorRuntime().wrap(function _callee$(_context2) {
101
- while (1) {
102
- switch (_context2.prev = _context2.next) {
103
- case 0:
104
- popupMountPointId = _ref.popupMountPointId, rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
105
- popupMountPoint = document.getElementById(popupMountPointId);
106
- if (!popupMountPoint) {
107
- popupMountPoint = document.createElement('div');
108
- popupMountPoint.id = popupMountPointId;
109
- popupMountPoint.setAttribute('data-testid', 'preview-modal');
110
- document.body.appendChild(popupMountPoint);
111
- }
112
- _context2.next = 5;
113
- return Promise.resolve().then(function () {
114
- return _interopRequireWildcard(require('../../../../../EmbedModal'));
115
- });
116
- case 5:
117
- Modal = _context2.sent;
118
- _reactDom.default.render( /*#__PURE__*/_react.default.createElement(_reactIntlNext.IntlProvider, {
119
- locale: "en"
120
- }, /*#__PURE__*/_react.default.createElement(Modal.default, (0, _extends2.default)({}, rest, {
121
- onClose: function onClose(_context) {
122
- if (popupMountPoint) {
123
- _reactDom.default.unmountComponentAtNode(popupMountPoint);
124
- }
125
- }
126
- }))), popupMountPoint);
127
- case 7:
128
- case "end":
129
- return _context2.stop();
130
- }
131
- }
132
- }, _callee);
133
- }));
134
- return _previewFunction.apply(this, arguments);
135
- }
136
60
  var _default = PreviewAction;
137
61
  exports.default = _default;