@atlaskit/smart-card 25.4.0 → 25.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/smart-card
2
2
 
3
+ ## 25.4.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`1d38688106e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/1d38688106e) - [ux] Moved out the implementation of the resolve function from useSmartCardActions into a separate internal hook useResolve. Added reload functionality for LozengeAction on a successful update
8
+ - [`0ee9370595a`](https://bitbucket.org/atlassian/atlassian-frontend/commits/0ee9370595a) - Update json-ld-types
9
+ - Updated dependencies
10
+
11
+ ## 25.4.1
12
+
13
+ ### Patch Changes
14
+
15
+ - [`ae2cba07a9a`](https://bitbucket.org/atlassian/atlassian-frontend/commits/ae2cba07a9a) - Removes prevented as a clickOutcome analytics attribute value and adds defaultPrevented as a replacement attribute.
16
+
3
17
  ## 25.4.0
4
18
 
5
19
  ### Minor Changes
@@ -12,116 +12,31 @@ var _outboundAuthFlowClient = require("@atlaskit/outbound-auth-flow-client");
12
12
  var _linkProvider = require("@atlaskit/link-provider");
13
13
  var _linkingCommon = require("@atlaskit/linking-common");
14
14
  var _helpers = require("../helpers");
15
- var _constants = require("./constants");
16
15
  var measure = _interopRequireWildcard(require("../../utils/performance"));
17
- var _jsonld = require("../../utils/jsonld");
18
- var _analytics = require("../analytics");
19
- var _constants2 = require("../../constants");
20
- var _extractLozengeText = require("../../extractors/common/lozenge/extractLozengeText");
16
+ var _constants = require("../../constants");
17
+ var _useResolve = _interopRequireDefault(require("../hooks/use-resolve"));
21
18
  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); }
22
19
  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; }
23
20
  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; }
24
21
  var useSmartCardActions = function useSmartCardActions(id, url, analytics) {
22
+ var resolveUrl = (0, _useResolve.default)();
25
23
  var _useSmartLinkContext = (0, _linkProvider.useSmartLinkContext)(),
26
24
  store = _useSmartLinkContext.store,
27
- connections = _useSmartLinkContext.connections,
28
- config = _useSmartLinkContext.config;
25
+ connections = _useSmartLinkContext.connections;
29
26
  var getState = store.getState,
30
27
  dispatch = store.dispatch;
31
28
  var _ref = getState()[url] || {
32
- status: _constants2.SmartLinkStatus.Pending,
29
+ status: _constants.SmartLinkStatus.Pending,
33
30
  details: undefined
34
31
  },
35
32
  details = _ref.details,
36
33
  status = _ref.status,
37
34
  metadataStatus = _ref.metadataStatus;
38
- var hasAuthFlowSupported = config.authFlow !== 'disabled';
39
- var hasData = !!(details && details.data);
40
35
  var setMetadataStatus = (0, _react.useCallback)(function (metadataStatus) {
41
36
  dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_UPDATE_METADATA_STATUS, {
42
37
  url: url
43
38
  }, undefined, undefined, metadataStatus));
44
39
  }, [dispatch, url]);
45
- var handleResolvedLinkError = (0, _react.useCallback)(function (url, error, response, isMetadataRequest) {
46
- // If metadata request then set metadata status, return and do not alter link status
47
- if (isMetadataRequest) {
48
- setMetadataStatus('errored');
49
- return;
50
- }
51
- if (error.kind === 'fatal') {
52
- // If there's no previous data in the store for this URL, then bail
53
- // out and let the editor handle fallbacks (returns to a blue link).
54
- if (!hasData && status !== 'resolved') {
55
- dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_ERROR, {
56
- url: url
57
- }, details, error));
58
- throw error;
59
- }
60
- // If we already have resolved data for this URL in the store, then
61
- // simply fallback to the previous data.
62
- if (hasData) {
63
- dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RESOLVED, {
64
- url: url
65
- }, details));
66
- }
67
- // Handle AuthErrors (user did not have access to resource) -
68
- // Missing AAID in ASAP claims, or missing UserContext, or 403 from downstream
69
- } else if (error.kind === 'auth') {
70
- dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RESOLVED, {
71
- url: url
72
- }, (0, _jsonld.getUnauthorizedJsonLd)()));
73
- } else {
74
- if (error.kind === 'fallback') {
75
- // Fallback to blue link with smart link formatting. Not part of reliability.
76
- dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_ERROR_FALLBACK, {
77
- url: url
78
- }, response, error));
79
- } else {
80
- // Fallback to blue link with smart link formatting. Part of reliability.
81
- dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_ERROR, {
82
- url: url
83
- }, undefined, error));
84
- }
85
- }
86
- }, [setMetadataStatus, hasData, status, dispatch, details]);
87
- var handleResolvedLinkResponse = (0, _react.useCallback)(function (resourceUrl, response) {
88
- var isReloading = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
89
- var isMetadataRequest = arguments.length > 3 ? arguments[3] : undefined;
90
- var hostname = new URL(resourceUrl).hostname;
91
- var nextStatus = response ? (0, _helpers.getStatus)(response) : 'fatal';
92
-
93
- // If we require authorization & do not have an authFlow available,
94
- // throw an error and render as a normal blue link.
95
- if ((nextStatus === 'unauthorized' || nextStatus === 'forbidden') && !hasAuthFlowSupported) {
96
- handleResolvedLinkError(resourceUrl, new _linkingCommon.APIError('fallback', hostname, _constants.ERROR_MESSAGE_OAUTH), response, isMetadataRequest);
97
- return;
98
- }
99
-
100
- // Handle any other errors
101
- if (nextStatus === 'fatal') {
102
- handleResolvedLinkError(resourceUrl, new _linkingCommon.APIError('fatal', hostname, _constants.ERROR_MESSAGE_FATAL), undefined, isMetadataRequest);
103
- return;
104
- }
105
-
106
- // Handle errors of any other kind in the metadata request response
107
- if (isMetadataRequest && nextStatus !== 'resolved') {
108
- handleResolvedLinkError(resourceUrl, new _linkingCommon.APIError('error', hostname, _constants.ERROR_MESSAGE_METADATA), response, isMetadataRequest);
109
- return;
110
- }
111
-
112
- //if a link resolves normally, metadata will also always be resolved
113
- setMetadataStatus('resolved');
114
- // Dispatch Analytics and resolved card action - including unauthorized states.
115
- if (isReloading) {
116
- dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RELOADING, {
117
- url: resourceUrl
118
- }, response));
119
- } else {
120
- dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RESOLVED, {
121
- url: resourceUrl
122
- }, response, undefined, undefined, isMetadataRequest));
123
- }
124
- }, [dispatch, handleResolvedLinkError, hasAuthFlowSupported, setMetadataStatus]);
125
40
  var resolve = (0, _react.useCallback)( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
126
41
  var resourceUrl,
127
42
  isReloading,
@@ -134,26 +49,14 @@ var useSmartCardActions = function useSmartCardActions(id, url, analytics) {
134
49
  resourceUrl = _args.length > 0 && _args[0] !== undefined ? _args[0] : url;
135
50
  isReloading = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
136
51
  isMetadataRequest = _args.length > 2 && _args[2] !== undefined ? _args[2] : false;
137
- if (!(isReloading || !hasData || isMetadataRequest)) {
138
- _context.next = 7;
139
- break;
140
- }
141
- return _context.abrupt("return", connections.client.fetchData(resourceUrl, isReloading).then(function (response) {
142
- return handleResolvedLinkResponse(resourceUrl, response, isReloading, isMetadataRequest);
143
- }).catch(function (error) {
144
- return handleResolvedLinkError(resourceUrl, error, undefined, isMetadataRequest);
145
- }));
146
- case 7:
147
- (0, _analytics.addMetadataToExperience)('smart-link-rendered', id, {
148
- cached: true
149
- });
150
- case 8:
52
+ return _context.abrupt("return", resolveUrl(resourceUrl, isReloading, isMetadataRequest, id));
53
+ case 4:
151
54
  case "end":
152
55
  return _context.stop();
153
56
  }
154
57
  }
155
58
  }, _callee);
156
- })), [url, hasData, connections.client, handleResolvedLinkResponse, handleResolvedLinkError, id]);
59
+ })), [id, resolveUrl, url]);
157
60
  var register = (0, _react.useCallback)(function () {
158
61
  if (!details) {
159
62
  dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RESOLVING, {
@@ -164,40 +67,15 @@ var useSmartCardActions = function useSmartCardActions(id, url, analytics) {
164
67
  return resolve();
165
68
  }, [details, resolve, dispatch, url, setMetadataStatus]);
166
69
  var reload = (0, _react.useCallback)(function () {
167
- var _details$data, _details$data$Type;
168
70
  var definitionId = (0, _helpers.getDefinitionId)(details);
169
-
170
- // Start: Smart link Actions experiment
171
- if (definitionId === 'jira-object-provider' && details !== null && details !== void 0 && (_details$data = details.data) !== null && _details$data !== void 0 && (_details$data$Type = _details$data['@type']) !== null && _details$data$Type !== void 0 && _details$data$Type.includes('atlassian:Task')) {
172
- // EDM-5149: This is part of actionable element experiment where we
173
- // reload jira issue link after embed view modal is closed.
174
- // In our component, `reload` is only used in auth flow which
175
- // jira link, being Atlassian product, would not fall into this category
176
- // and would not be reloaded in normal smart link context.
177
- // The code from resolve is duplicated here to avoid changing the response
178
- // shape of resolve.
179
- var previousJiraStatus = (0, _extractLozengeText.extractLozengeText)(details);
180
- connections.client.fetchData(url, true).then(function (response) {
181
- handleResolvedLinkResponse(url, response, true, false);
182
- var jiraStatus = (0, _extractLozengeText.extractLozengeText)(response);
183
- analytics.track.linkUpdated({
184
- actionSubjectId: 'jiraIssueStatus',
185
- previousJiraStatus: previousJiraStatus,
186
- jiraStatus: jiraStatus
187
- });
188
- }).catch(function (error) {
189
- return handleResolvedLinkError(url, error, undefined, false);
190
- });
191
- }
192
- // End: Smart ink Actions experiment
193
- else if (definitionId) {
71
+ if (definitionId) {
194
72
  (0, _helpers.getByDefinitionId)(definitionId, getState()).map(function (url) {
195
73
  return resolve(url, true);
196
74
  });
197
75
  } else {
198
76
  resolve(url, true);
199
77
  }
200
- }, [details, connections.client, url, handleResolvedLinkResponse, analytics.track, handleResolvedLinkError, getState, resolve]);
78
+ }, [details, url, getState, resolve]);
201
79
  var loadMetadata = (0, _react.useCallback)(function () {
202
80
  //metadataStatus will be undefined for SSR links only
203
81
  if (metadataStatus === undefined) {
@@ -0,0 +1,169 @@
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.default = void 0;
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ var _react = require("react");
11
+ var _analytics = require("../../analytics");
12
+ var _helpers = require("../../helpers");
13
+ var _linkingCommon = require("@atlaskit/linking-common");
14
+ var _constants = require("../../actions/constants");
15
+ var _jsonld = require("../../../utils/jsonld");
16
+ var _constants2 = require("../../../constants");
17
+ var _linkProvider = require("@atlaskit/link-provider");
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
+ var useResolve = function useResolve() {
20
+ // Request JSON-LD data for the card from ORS, if it has extended
21
+ // its cache lifespan OR there is no data for it currently. Once the data
22
+ // has come back asynchronously, dispatch the resolved action for the card.
23
+ var _useSmartLinkContext = (0, _linkProvider.useSmartLinkContext)(),
24
+ store = _useSmartLinkContext.store,
25
+ connections = _useSmartLinkContext.connections,
26
+ config = _useSmartLinkContext.config;
27
+ var getState = store.getState,
28
+ dispatch = store.dispatch;
29
+ var hasAuthFlowSupported = config.authFlow !== 'disabled';
30
+ var setMetadataStatus = (0, _react.useCallback)(function (url, metadataStatus) {
31
+ dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_UPDATE_METADATA_STATUS, {
32
+ url: url
33
+ }, undefined, undefined, metadataStatus));
34
+ }, [dispatch]);
35
+ var handleResolvedLinkError = (0, _react.useCallback)(function (url, error, response, isMetadataRequest) {
36
+ var _ref = getState()[url] || {
37
+ status: _constants2.SmartLinkStatus.Pending,
38
+ details: undefined
39
+ },
40
+ details = _ref.details;
41
+ var hasData = !!(details && details.data);
42
+
43
+ // If metadata request then set metadata status, return and do not alter link status
44
+ if (isMetadataRequest) {
45
+ setMetadataStatus(url, 'errored');
46
+ return;
47
+ }
48
+ if (error.kind === 'fatal') {
49
+ // If there's no previous data in the store for this URL, then bail
50
+ // out and let the editor handle fallbacks (returns to a blue link).
51
+ if (!hasData && status !== 'resolved') {
52
+ dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_ERROR, {
53
+ url: url
54
+ }, details, error));
55
+ throw error;
56
+ }
57
+ // If we already have resolved data for this URL in the store, then
58
+ // simply fallback to the previous data.
59
+ if (hasData) {
60
+ dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RESOLVED, {
61
+ url: url
62
+ }, details));
63
+ }
64
+ // Handle AuthErrors (user did not have access to resource) -
65
+ // Missing AAID in ASAP claims, or missing UserContext, or 403 from downstream
66
+ } else if (error.kind === 'auth') {
67
+ dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RESOLVED, {
68
+ url: url
69
+ }, (0, _jsonld.getUnauthorizedJsonLd)()));
70
+ } else {
71
+ if (error.kind === 'fallback') {
72
+ // Fallback to blue link with smart link formatting. Not part of reliability.
73
+ dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_ERROR_FALLBACK, {
74
+ url: url
75
+ }, response, error));
76
+ } else {
77
+ // Fallback to blue link with smart link formatting. Part of reliability.
78
+ dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_ERROR, {
79
+ url: url
80
+ }, undefined, error));
81
+ }
82
+ }
83
+ }, [getState, setMetadataStatus, dispatch]);
84
+ var handleResolvedLinkResponse = (0, _react.useCallback)(function (resourceUrl, response) {
85
+ var isReloading = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
86
+ var isMetadataRequest = arguments.length > 3 ? arguments[3] : undefined;
87
+ var hostname = new URL(resourceUrl).hostname;
88
+ var nextStatus = response ? (0, _helpers.getStatus)(response) : 'fatal';
89
+
90
+ // If we require authorization & do not have an authFlow available,
91
+ // throw an error and render as a normal blue link.
92
+ if ((nextStatus === 'unauthorized' || nextStatus === 'forbidden') && !hasAuthFlowSupported) {
93
+ handleResolvedLinkError(resourceUrl, new _linkingCommon.APIError('fallback', hostname, _constants.ERROR_MESSAGE_OAUTH), response, isMetadataRequest);
94
+ return;
95
+ }
96
+
97
+ // Handle any other errors
98
+ if (nextStatus === 'fatal') {
99
+ handleResolvedLinkError(resourceUrl, new _linkingCommon.APIError('fatal', hostname, _constants.ERROR_MESSAGE_FATAL), undefined, isMetadataRequest);
100
+ return;
101
+ }
102
+
103
+ // Handle errors of any other kind in the metadata request response
104
+ if (isMetadataRequest && nextStatus !== 'resolved') {
105
+ handleResolvedLinkError(resourceUrl, new _linkingCommon.APIError('error', hostname, _constants.ERROR_MESSAGE_METADATA), response, isMetadataRequest);
106
+ return;
107
+ }
108
+
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
+ }
121
+ }, [dispatch, handleResolvedLinkError, hasAuthFlowSupported, setMetadataStatus]);
122
+ return (0, _react.useCallback)( /*#__PURE__*/function () {
123
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
124
+ var isReloading,
125
+ isMetadataRequest,
126
+ id,
127
+ _ref3,
128
+ details,
129
+ hasData,
130
+ _args = arguments;
131
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
132
+ while (1) {
133
+ switch (_context.prev = _context.next) {
134
+ case 0:
135
+ isReloading = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;
136
+ isMetadataRequest = _args.length > 2 && _args[2] !== undefined ? _args[2] : false;
137
+ id = _args.length > 3 && _args[3] !== undefined ? _args[3] : '';
138
+ _ref3 = getState()[url] || {
139
+ status: _constants2.SmartLinkStatus.Pending,
140
+ details: undefined
141
+ }, details = _ref3.details;
142
+ hasData = !!(details && details.data);
143
+ if (!(isReloading || !hasData || isMetadataRequest)) {
144
+ _context.next = 9;
145
+ break;
146
+ }
147
+ return _context.abrupt("return", connections.client.fetchData(url, isReloading).then(function (response) {
148
+ return handleResolvedLinkResponse(url, response, isReloading, isMetadataRequest);
149
+ }).catch(function (error) {
150
+ return handleResolvedLinkError(url, error, undefined, isMetadataRequest);
151
+ }));
152
+ case 9:
153
+ (0, _analytics.addMetadataToExperience)('smart-link-rendered', id, {
154
+ cached: true
155
+ });
156
+ case 10:
157
+ case "end":
158
+ return _context.stop();
159
+ }
160
+ }
161
+ }, _callee);
162
+ }));
163
+ return function (_x) {
164
+ return _ref2.apply(this, arguments);
165
+ };
166
+ }(), [connections.client, getState, handleResolvedLinkError, handleResolvedLinkResponse]);
167
+ };
168
+ var _default = useResolve;
169
+ exports.default = _default;
@@ -26,9 +26,7 @@ function getLinkClickOutcome(e, clickType) {
26
26
  var _browser = (0, _userAgent.browser)(),
27
27
  mac = _browser.mac,
28
28
  safari = _browser.safari;
29
- if (e.defaultPrevented) {
30
- return 'prevented';
31
- }
29
+
32
30
  /**
33
31
  * If the link/parent is content editable then left click won't have typical effect
34
32
  */
@@ -76,12 +74,13 @@ function getLinkClickOutcome(e, clickType) {
76
74
  return 'contextMenu';
77
75
  }
78
76
  }
79
- return '_unknown';
77
+ return 'unknown';
80
78
  }
81
79
  var linkClickedEvent = function linkClickedEvent(_ref) {
82
80
  var clickType = _ref.clickType,
83
81
  clickOutcome = _ref.clickOutcome,
84
- keysHeld = _ref.keysHeld;
82
+ keysHeld = _ref.keysHeld,
83
+ defaultPrevented = _ref.defaultPrevented;
85
84
  return {
86
85
  action: 'clicked',
87
86
  actionSubject: 'link',
@@ -89,7 +88,8 @@ var linkClickedEvent = function linkClickedEvent(_ref) {
89
88
  attributes: {
90
89
  clickType: clickType,
91
90
  clickOutcome: clickOutcome,
92
- keysHeld: keysHeld
91
+ keysHeld: keysHeld,
92
+ defaultPrevented: defaultPrevented
93
93
  }
94
94
  };
95
95
  };
@@ -100,10 +100,12 @@ var createLinkClickedPayload = function createLinkClickedPayload(event) {
100
100
  }
101
101
  var clickOutcome = getLinkClickOutcome(event, clickType);
102
102
  var keysHeld = getKeys(event);
103
+ var defaultPrevented = event.defaultPrevented;
103
104
  return linkClickedEvent({
104
105
  clickType: clickType,
105
106
  clickOutcome: clickOutcome,
106
- keysHeld: keysHeld
107
+ keysHeld: keysHeld,
108
+ defaultPrevented: defaultPrevented
107
109
  });
108
110
  };
109
111
  exports.createLinkClickedPayload = createLinkClickedPayload;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "25.4.0",
3
+ "version": "25.4.2",
4
4
  "sideEffects": false
5
5
  }
@@ -21,6 +21,7 @@ var _useInvoke = _interopRequireDefault(require("../../../../../state/hooks/use-
21
21
  var _types = require("../../../../../state/hooks/use-invoke/types");
22
22
  var _extractLozengeActionItems = _interopRequireDefault(require("../../../../../extractors/action/extract-lozenge-action-items"));
23
23
  var _createStatusUpdateRequest = _interopRequireDefault(require("../../../../../utils/actions/create-status-update-request"));
24
+ var _useResolve = _interopRequireDefault(require("../../../../../state/hooks/use-resolve"));
24
25
  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
26
  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
27
  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; } /** @jsx jsx */
@@ -58,6 +59,7 @@ var LozengeAction = function LozengeAction(_ref) {
58
59
  errorCode = _useState10[0],
59
60
  setErrorCode = _useState10[1];
60
61
  var invoke = (0, _useInvoke.default)();
62
+ var reload = (0, _useResolve.default)();
61
63
  var handleOpenChange = (0, _react2.useCallback)( /*#__PURE__*/function () {
62
64
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(args) {
63
65
  var responseItems, validItems;
@@ -117,43 +119,51 @@ var LozengeAction = function LozengeAction(_ref) {
117
119
  }, [appearance, testId, text]);
118
120
  var handleItemClick = (0, _react2.useCallback)( /*#__PURE__*/function () {
119
121
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(id) {
120
- var request;
122
+ var updateAction, request, _ref4, url, linkId;
121
123
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
122
124
  while (1) {
123
125
  switch (_context2.prev = _context2.next) {
124
126
  case 0:
125
127
  _context2.prev = 0;
126
- if (!(action !== null && action !== void 0 && action.update && id)) {
127
- _context2.next = 8;
128
+ updateAction = action === null || action === void 0 ? void 0 : action.update;
129
+ if (!(updateAction && id)) {
130
+ _context2.next = 13;
128
131
  break;
129
132
  }
130
133
  setIsLoading(true);
131
- request = (0, _createStatusUpdateRequest.default)(action.update, id);
132
- _context2.next = 6;
134
+ request = (0, _createStatusUpdateRequest.default)(updateAction, id);
135
+ _context2.next = 7;
133
136
  return invoke(request);
134
- case 6:
137
+ case 7:
135
138
  setIsLoading(false);
136
139
  setIsOpen(false);
137
- case 8:
138
- _context2.next = 14;
140
+ _ref4 = updateAction.details || {}, url = _ref4.url, linkId = _ref4.id;
141
+ if (!url) {
142
+ _context2.next = 13;
143
+ break;
144
+ }
145
+ _context2.next = 13;
146
+ return reload(url, true, undefined, linkId);
147
+ case 13:
148
+ _context2.next = 19;
139
149
  break;
140
- case 10:
141
- _context2.prev = 10;
150
+ case 15:
151
+ _context2.prev = 15;
142
152
  _context2.t0 = _context2["catch"](0);
143
153
  // TODO: EDM-6261: Error state
144
154
  setIsLoading(false);
145
155
  setErrorCode(_types.InvokeActionError.Unknown);
146
- case 14:
156
+ case 19:
147
157
  case "end":
148
158
  return _context2.stop();
149
159
  }
150
160
  }
151
- }, _callee2, null, [[0, 10]]);
161
+ }, _callee2, null, [[0, 15]]);
152
162
  }));
153
163
  return function (_x2) {
154
164
  return _ref3.apply(this, arguments);
155
165
  };
156
- }(), [action === null || action === void 0 ? void 0 : action.update, invoke]);
166
+ }(), [action === null || action === void 0 ? void 0 : action.update, invoke, reload]);
157
167
  var dropdownItemGroup = (0, _react2.useMemo)(function () {
158
168
  if (errorCode) {
159
169
  return (0, _react.jsx)(_lozengeActionError.default, {