@atlaskit/smart-card 18.0.21 → 19.0.1

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 (257) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/cjs/client/index.js +6 -379
  3. package/dist/cjs/constants.js +4 -4
  4. package/dist/cjs/extractors/embed/index.js +2 -2
  5. package/dist/cjs/extractors/hover/extractMetadata.js +31 -0
  6. package/dist/cjs/index.js +7 -13
  7. package/dist/cjs/state/actions/constants.js +1 -13
  8. package/dist/cjs/state/actions/index.js +20 -22
  9. package/dist/cjs/state/analytics/useSmartLinkAnalytics.js +2 -2
  10. package/dist/cjs/state/config/index.js +2 -2
  11. package/dist/cjs/state/helpers.js +1 -9
  12. package/dist/cjs/state/hooks/usePrefetch.js +2 -2
  13. package/dist/cjs/state/index.js +4 -4
  14. package/dist/cjs/state/renderers/index.js +2 -2
  15. package/dist/cjs/state/store/index.js +5 -5
  16. package/dist/cjs/utils/mocks.js +2 -2
  17. package/dist/cjs/utils/test-utils.js +2 -2
  18. package/dist/cjs/version.json +1 -1
  19. package/dist/cjs/view/FlexibleCard/components/actions/action/index.js +2 -2
  20. package/dist/cjs/view/FlexibleCard/components/blocks/action-group/index.js +1 -0
  21. package/dist/cjs/view/FlexibleCard/components/blocks/block/index.js +3 -2
  22. package/dist/cjs/view/FlexibleCard/components/blocks/element-group/index.js +1 -0
  23. package/dist/cjs/view/FlexibleCard/components/blocks/footer-block/index.js +1 -0
  24. package/dist/cjs/view/FlexibleCard/components/blocks/metadata-block/index.js +1 -0
  25. package/dist/cjs/view/FlexibleCard/components/blocks/preview-block/index.js +1 -0
  26. package/dist/cjs/view/FlexibleCard/components/blocks/snippet-block/index.js +1 -0
  27. package/dist/cjs/view/FlexibleCard/components/blocks/title-block/index.js +2 -1
  28. package/dist/cjs/view/FlexibleCard/components/container/index.js +19 -6
  29. package/dist/cjs/view/FlexibleCard/components/container/layered-link/index.js +5 -0
  30. package/dist/cjs/view/FlexibleCard/components/elements/avatar-group/index.js +2 -2
  31. package/dist/cjs/view/FlexibleCard/components/elements/badge/index.js +2 -2
  32. package/dist/cjs/view/FlexibleCard/components/elements/date-time/index.js +2 -2
  33. package/dist/cjs/view/FlexibleCard/components/elements/icon/index.js +2 -2
  34. package/dist/cjs/view/FlexibleCard/components/elements/index.js +2 -2
  35. package/dist/cjs/view/FlexibleCard/components/elements/link/index.js +3 -3
  36. package/dist/cjs/view/FlexibleCard/components/elements/lozenge/index.js +2 -2
  37. package/dist/cjs/view/FlexibleCard/components/elements/media/index.js +2 -2
  38. package/dist/cjs/view/FlexibleCard/components/elements/text/index.js +2 -2
  39. package/dist/cjs/view/HoverCard/index.js +11 -2
  40. package/dist/cjs/view/HoverCard/utils.js +36 -0
  41. package/dist/es2019/client/index.js +1 -214
  42. package/dist/es2019/constants.js +4 -4
  43. package/dist/es2019/extractors/embed/index.js +1 -1
  44. package/dist/es2019/extractors/hover/extractMetadata.js +18 -0
  45. package/dist/es2019/index.js +4 -4
  46. package/dist/es2019/state/actions/constants.js +0 -6
  47. package/dist/es2019/state/actions/index.js +4 -4
  48. package/dist/es2019/state/analytics/useSmartLinkAnalytics.js +1 -1
  49. package/dist/es2019/state/config/index.js +1 -1
  50. package/dist/es2019/state/helpers.js +0 -5
  51. package/dist/es2019/state/hooks/usePrefetch.js +1 -1
  52. package/dist/es2019/state/index.js +1 -1
  53. package/dist/es2019/state/renderers/index.js +1 -1
  54. package/dist/es2019/state/store/index.js +2 -2
  55. package/dist/es2019/utils/mocks.js +1 -1
  56. package/dist/es2019/utils/test-utils.js +1 -1
  57. package/dist/es2019/version.json +1 -1
  58. package/dist/es2019/view/FlexibleCard/components/actions/action/index.js +2 -2
  59. package/dist/es2019/view/FlexibleCard/components/blocks/action-group/index.js +1 -0
  60. package/dist/es2019/view/FlexibleCard/components/blocks/block/index.js +3 -2
  61. package/dist/es2019/view/FlexibleCard/components/blocks/element-group/index.js +1 -0
  62. package/dist/es2019/view/FlexibleCard/components/blocks/footer-block/index.js +1 -0
  63. package/dist/es2019/view/FlexibleCard/components/blocks/metadata-block/index.js +1 -0
  64. package/dist/es2019/view/FlexibleCard/components/blocks/preview-block/index.js +1 -0
  65. package/dist/es2019/view/FlexibleCard/components/blocks/snippet-block/index.js +1 -0
  66. package/dist/es2019/view/FlexibleCard/components/blocks/title-block/index.js +2 -1
  67. package/dist/es2019/view/FlexibleCard/components/container/index.js +19 -6
  68. package/dist/es2019/view/FlexibleCard/components/container/layered-link/index.js +5 -0
  69. package/dist/es2019/view/FlexibleCard/components/elements/avatar-group/index.js +2 -2
  70. package/dist/es2019/view/FlexibleCard/components/elements/badge/index.js +2 -2
  71. package/dist/es2019/view/FlexibleCard/components/elements/date-time/index.js +2 -2
  72. package/dist/es2019/view/FlexibleCard/components/elements/icon/index.js +2 -2
  73. package/dist/es2019/view/FlexibleCard/components/elements/index.js +2 -2
  74. package/dist/es2019/view/FlexibleCard/components/elements/link/index.js +3 -3
  75. package/dist/es2019/view/FlexibleCard/components/elements/lozenge/index.js +2 -2
  76. package/dist/es2019/view/FlexibleCard/components/elements/media/index.js +2 -2
  77. package/dist/es2019/view/FlexibleCard/components/elements/text/index.js +2 -2
  78. package/dist/es2019/view/HoverCard/index.js +27 -18
  79. package/dist/es2019/view/HoverCard/utils.js +27 -0
  80. package/dist/esm/client/index.js +1 -360
  81. package/dist/esm/constants.js +4 -4
  82. package/dist/esm/extractors/embed/index.js +1 -1
  83. package/dist/esm/extractors/hover/extractMetadata.js +22 -0
  84. package/dist/esm/index.js +4 -4
  85. package/dist/esm/state/actions/constants.js +0 -6
  86. package/dist/esm/state/actions/index.js +4 -4
  87. package/dist/esm/state/analytics/useSmartLinkAnalytics.js +1 -1
  88. package/dist/esm/state/config/index.js +1 -1
  89. package/dist/esm/state/helpers.js +0 -5
  90. package/dist/esm/state/hooks/usePrefetch.js +1 -1
  91. package/dist/esm/state/index.js +1 -1
  92. package/dist/esm/state/renderers/index.js +1 -1
  93. package/dist/esm/state/store/index.js +2 -2
  94. package/dist/esm/utils/mocks.js +1 -1
  95. package/dist/esm/utils/test-utils.js +1 -1
  96. package/dist/esm/version.json +1 -1
  97. package/dist/esm/view/FlexibleCard/components/actions/action/index.js +2 -2
  98. package/dist/esm/view/FlexibleCard/components/blocks/action-group/index.js +1 -0
  99. package/dist/esm/view/FlexibleCard/components/blocks/block/index.js +3 -2
  100. package/dist/esm/view/FlexibleCard/components/blocks/element-group/index.js +1 -0
  101. package/dist/esm/view/FlexibleCard/components/blocks/footer-block/index.js +1 -0
  102. package/dist/esm/view/FlexibleCard/components/blocks/metadata-block/index.js +1 -0
  103. package/dist/esm/view/FlexibleCard/components/blocks/preview-block/index.js +1 -0
  104. package/dist/esm/view/FlexibleCard/components/blocks/snippet-block/index.js +1 -0
  105. package/dist/esm/view/FlexibleCard/components/blocks/title-block/index.js +2 -1
  106. package/dist/esm/view/FlexibleCard/components/container/index.js +19 -6
  107. package/dist/esm/view/FlexibleCard/components/container/layered-link/index.js +5 -0
  108. package/dist/esm/view/FlexibleCard/components/elements/avatar-group/index.js +2 -2
  109. package/dist/esm/view/FlexibleCard/components/elements/badge/index.js +2 -2
  110. package/dist/esm/view/FlexibleCard/components/elements/date-time/index.js +2 -2
  111. package/dist/esm/view/FlexibleCard/components/elements/icon/index.js +2 -2
  112. package/dist/esm/view/FlexibleCard/components/elements/index.js +2 -2
  113. package/dist/esm/view/FlexibleCard/components/elements/link/index.js +3 -3
  114. package/dist/esm/view/FlexibleCard/components/elements/lozenge/index.js +2 -2
  115. package/dist/esm/view/FlexibleCard/components/elements/media/index.js +2 -2
  116. package/dist/esm/view/FlexibleCard/components/elements/text/index.js +2 -2
  117. package/dist/esm/view/HoverCard/index.js +10 -3
  118. package/dist/esm/view/HoverCard/utils.js +27 -0
  119. package/dist/types/__tests_external__/page-objects/BaseCard.d.ts +1 -2
  120. package/dist/types/client/index.d.ts +1 -18
  121. package/dist/types/constants.d.ts +4 -4
  122. package/dist/types/extractors/block/index.d.ts +1 -1
  123. package/dist/types/extractors/common/title-prefix/extractTitlePrefix.d.ts +1 -1
  124. package/dist/types/extractors/flexible/icon/extract-icon-renderer.d.ts +1 -1
  125. package/dist/types/extractors/flexible/icon/index.d.ts +1 -1
  126. package/dist/types/extractors/flexible/index.d.ts +1 -1
  127. package/dist/types/extractors/hover/extractMetadata.d.ts +3 -0
  128. package/dist/types/extractors/inline/index.d.ts +1 -1
  129. package/dist/types/index.d.ts +6 -6
  130. package/dist/types/model/invoke-opts.d.ts +1 -14
  131. package/dist/types/state/actions/constants.d.ts +0 -6
  132. package/dist/types/state/actions/types.d.ts +2 -13
  133. package/dist/types/state/analytics/useSmartLinkAnalytics.d.ts +1 -2
  134. package/dist/types/state/config/index.d.ts +1 -1
  135. package/dist/types/state/helpers.d.ts +1 -3
  136. package/dist/types/state/hooks/useSmartLink.d.ts +6 -6
  137. package/dist/types/state/index.d.ts +3 -3
  138. package/dist/types/state/reducers/types.d.ts +1 -1
  139. package/dist/types/state/renderers/index.d.ts +1 -1
  140. package/dist/types/state/store/index.d.ts +2 -2
  141. package/dist/types/state/types.d.ts +1 -1
  142. package/dist/types/types.d.ts +2 -2
  143. package/dist/types/utils/analytics/analytics.d.ts +1 -1
  144. package/dist/types/utils/analytics/index.d.ts +1 -2
  145. package/dist/types/utils/performance.d.ts +1 -1
  146. package/dist/types/view/BlockCard/types.d.ts +1 -1
  147. package/dist/types/view/Card/types.d.ts +2 -3
  148. package/dist/types/view/FlexibleCard/components/actions/action/index.d.ts +2 -2
  149. package/dist/types/view/FlexibleCard/components/actions/action/types.d.ts +43 -0
  150. package/dist/types/view/FlexibleCard/components/blocks/action-group/index.d.ts +1 -0
  151. package/dist/types/view/FlexibleCard/components/blocks/action-group/types.d.ts +25 -0
  152. package/dist/types/view/FlexibleCard/components/blocks/block/index.d.ts +3 -2
  153. package/dist/types/view/FlexibleCard/components/blocks/element-group/index.d.ts +1 -0
  154. package/dist/types/view/FlexibleCard/components/blocks/footer-block/index.d.ts +1 -0
  155. package/dist/types/view/FlexibleCard/components/blocks/footer-block/types.d.ts +8 -2
  156. package/dist/types/view/FlexibleCard/components/blocks/metadata-block/index.d.ts +1 -0
  157. package/dist/types/view/FlexibleCard/components/blocks/metadata-block/types.d.ts +22 -2
  158. package/dist/types/view/FlexibleCard/components/blocks/preview-block/index.d.ts +1 -0
  159. package/dist/types/view/FlexibleCard/components/blocks/snippet-block/index.d.ts +1 -0
  160. package/dist/types/view/FlexibleCard/components/blocks/snippet-block/types.d.ts +6 -2
  161. package/dist/types/view/FlexibleCard/components/blocks/title-block/index.d.ts +2 -1
  162. package/dist/types/view/FlexibleCard/components/blocks/title-block/types.d.ts +63 -13
  163. package/dist/types/view/FlexibleCard/components/blocks/types.d.ts +68 -2
  164. package/dist/types/view/FlexibleCard/components/common/loading-skeleton/types.d.ts +5 -0
  165. package/dist/types/view/FlexibleCard/components/container/index.d.ts +5 -1
  166. package/dist/types/view/FlexibleCard/components/container/layered-link/index.d.ts +5 -0
  167. package/dist/types/view/FlexibleCard/components/container/types.d.ts +20 -10
  168. package/dist/types/view/FlexibleCard/components/elements/avatar-group/index.d.ts +2 -2
  169. package/dist/types/view/FlexibleCard/components/elements/avatar-group/types.d.ts +12 -0
  170. package/dist/types/view/FlexibleCard/components/elements/badge/index.d.ts +2 -2
  171. package/dist/types/view/FlexibleCard/components/elements/badge/types.d.ts +10 -0
  172. package/dist/types/view/FlexibleCard/components/elements/date-time/index.d.ts +2 -2
  173. package/dist/types/view/FlexibleCard/components/elements/date-time/types.d.ts +6 -0
  174. package/dist/types/view/FlexibleCard/components/elements/icon/index.d.ts +2 -2
  175. package/dist/types/view/FlexibleCard/components/elements/icon/types.d.ts +16 -3
  176. package/dist/types/view/FlexibleCard/components/elements/index.d.ts +2 -2
  177. package/dist/types/view/FlexibleCard/components/elements/link/index.d.ts +3 -3
  178. package/dist/types/view/FlexibleCard/components/elements/link/types.d.ts +21 -1
  179. package/dist/types/view/FlexibleCard/components/elements/lozenge/index.d.ts +2 -2
  180. package/dist/types/view/FlexibleCard/components/elements/lozenge/types.d.ts +6 -0
  181. package/dist/types/view/FlexibleCard/components/elements/media/index.d.ts +2 -2
  182. package/dist/types/view/FlexibleCard/components/elements/media/types.d.ts +6 -0
  183. package/dist/types/view/FlexibleCard/components/elements/text/index.d.ts +2 -2
  184. package/dist/types/view/FlexibleCard/components/elements/text/types.d.ts +10 -0
  185. package/dist/types/view/FlexibleCard/components/elements/types.d.ts +11 -0
  186. package/dist/types/view/FlexibleCard/components/types.d.ts +1 -0
  187. package/dist/types/view/FlexibleCard/types.d.ts +73 -3
  188. package/dist/types/view/FlexibleCard/utils.d.ts +1 -1
  189. package/dist/types/view/HoverCard/types.d.ts +5 -0
  190. package/dist/types/view/HoverCard/utils.d.ts +2 -0
  191. package/dist/types/view/InlineCard/types.d.ts +1 -1
  192. package/docs-helpers/flexible-ui-action-item.tsx +6 -0
  193. package/docs-helpers/flexible-ui-actions-prop.tsx +6 -0
  194. package/docs-helpers/flexible-ui-element-item.tsx +6 -0
  195. package/docs-helpers/flexible-ui-prop.tsx +6 -0
  196. package/docs-helpers/flexible-ui.tsx +28 -0
  197. package/package.json +3 -9
  198. package/dist/cjs/client/api.js +0 -119
  199. package/dist/cjs/client/errors.js +0 -55
  200. package/dist/cjs/client/types/index.js +0 -5
  201. package/dist/cjs/client/types/requests.js +0 -5
  202. package/dist/cjs/client/types/responses.js +0 -31
  203. package/dist/cjs/client/utils/environments.js +0 -47
  204. package/dist/cjs/providers/editor/index.js +0 -283
  205. package/dist/cjs/providers/editor/transformer.js +0 -90
  206. package/dist/cjs/providers/editor/types.js +0 -5
  207. package/dist/cjs/state/actions/helpers.js +0 -18
  208. package/dist/cjs/state/context/index.js +0 -34
  209. package/dist/cjs/state/context/provider.js +0 -74
  210. package/dist/cjs/state/context/types.js +0 -5
  211. package/dist/cjs/state/reducers/index.js +0 -89
  212. package/dist/cjs/state/store/types.js +0 -5
  213. package/dist/es2019/client/api.js +0 -38
  214. package/dist/es2019/client/errors.js +0 -19
  215. package/dist/es2019/client/types/index.js +0 -1
  216. package/dist/es2019/client/types/requests.js +0 -1
  217. package/dist/es2019/client/types/responses.js +0 -19
  218. package/dist/es2019/client/utils/environments.js +0 -33
  219. package/dist/es2019/providers/editor/index.js +0 -82
  220. package/dist/es2019/providers/editor/transformer.js +0 -57
  221. package/dist/es2019/providers/editor/types.js +0 -1
  222. package/dist/es2019/state/actions/helpers.js +0 -8
  223. package/dist/es2019/state/context/index.js +0 -14
  224. package/dist/es2019/state/context/provider.js +0 -51
  225. package/dist/es2019/state/context/types.js +0 -1
  226. package/dist/es2019/state/reducers/index.js +0 -74
  227. package/dist/es2019/state/store/types.js +0 -1
  228. package/dist/esm/client/api.js +0 -98
  229. package/dist/esm/client/errors.js +0 -40
  230. package/dist/esm/client/types/index.js +0 -1
  231. package/dist/esm/client/types/requests.js +0 -1
  232. package/dist/esm/client/types/responses.js +0 -19
  233. package/dist/esm/client/utils/environments.js +0 -33
  234. package/dist/esm/providers/editor/index.js +0 -257
  235. package/dist/esm/providers/editor/transformer.js +0 -79
  236. package/dist/esm/providers/editor/types.js +0 -1
  237. package/dist/esm/state/actions/helpers.js +0 -9
  238. package/dist/esm/state/context/index.js +0 -14
  239. package/dist/esm/state/context/provider.js +0 -50
  240. package/dist/esm/state/context/types.js +0 -1
  241. package/dist/esm/state/reducers/index.js +0 -69
  242. package/dist/esm/state/store/types.js +0 -1
  243. package/dist/types/client/api.d.ts +0 -5
  244. package/dist/types/client/errors.d.ts +0 -9
  245. package/dist/types/client/types/index.d.ts +0 -13
  246. package/dist/types/client/types/requests.d.ts +0 -9
  247. package/dist/types/client/types/responses.d.ts +0 -19
  248. package/dist/types/client/utils/environments.d.ts +0 -12
  249. package/dist/types/providers/editor/index.d.ts +0 -22
  250. package/dist/types/providers/editor/transformer.d.ts +0 -8
  251. package/dist/types/providers/editor/types.d.ts +0 -19
  252. package/dist/types/state/actions/helpers.d.ts +0 -2
  253. package/dist/types/state/context/index.d.ts +0 -8
  254. package/dist/types/state/context/provider.d.ts +0 -5
  255. package/dist/types/state/context/types.d.ts +0 -39
  256. package/dist/types/state/reducers/index.d.ts +0 -4
  257. package/dist/types/state/store/types.d.ts +0 -18
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getSimulatedMetadata = void 0;
7
+
8
+ var getSimulatedMetadata = function getSimulatedMetadata(extensionKey) {
9
+ switch (extensionKey) {
10
+ case 'confluence-object-provider':
11
+ return {
12
+ metadata: {
13
+ primary: ['AuthorGroup', 'CreatedBy', 'CommentCount', 'ReactCount'],
14
+ secondary: []
15
+ }
16
+ };
17
+
18
+ case 'jira-object-provider':
19
+ return {
20
+ metadata: {
21
+ primary: ['AuthorGroup', 'State', 'Priority'],
22
+ secondary: []
23
+ }
24
+ };
25
+
26
+ default:
27
+ return {
28
+ metadata: {
29
+ primary: ['ModifiedOn'],
30
+ secondary: []
31
+ }
32
+ };
33
+ }
34
+ };
35
+
36
+ exports.getSimulatedMetadata = getSimulatedMetadata;
@@ -1,214 +1 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- // import setimmediate to temporary fix dataloader 2.0.0 bug
3
- // @see https://github.com/graphql/dataloader/issues/249
4
- import 'setimmediate';
5
- import DataLoader from 'dataloader';
6
- import retry from 'async-retry';
7
- import * as api from './api';
8
- import { APIError } from './errors';
9
- import { getResolverUrl } from './utils/environments';
10
- import pThrottle from 'p-throttle';
11
- import { isSuccessfulResponse, isErrorResponse } from './types/responses';
12
- const MAX_BATCH_SIZE = 50;
13
- const MIN_TIME_BETWEEN_BATCHES = 250;
14
- export default class CardClient {
15
- constructor(envKey) {
16
- _defineProperty(this, "batchResolve", async urls => {
17
- // De-duplicate requested URLs (see `this.createLoader` for more detail).
18
- const deDuplicatedUrls = [...new Set(urls)];
19
- let resolvedUrls = [];
20
-
21
- try {
22
- // Ask the backend to resolve the URLs for us.
23
- resolvedUrls = await api.request('post', `${this.resolverUrl}/resolve/batch`, deDuplicatedUrls.map(resourceUrl => ({
24
- resourceUrl
25
- })));
26
- } catch (error) {
27
- // we make sure we return a valid dataloader response by creating an error
28
- // response for each url
29
- resolvedUrls = urls.map(() => {
30
- const status = isErrorResponse(error) ? error.status : 500;
31
- const errorResponse = {
32
- status,
33
- error
34
- };
35
- return errorResponse;
36
- });
37
- } // Reduce into a map to make accessing faster and easier.
38
-
39
-
40
- const map = {}; // NOTE: the batch endpoint returns the URLs in the same order they were given.
41
-
42
- for (let i = 0; i < deDuplicatedUrls.length; ++i) {
43
- const url = deDuplicatedUrls[i];
44
- const data = resolvedUrls[i];
45
- map[url] = data;
46
- } // Reconvert list back into the original order in which it was given to us.
47
-
48
-
49
- return urls.map(originalUrl => map[originalUrl]);
50
- });
51
-
52
- this.resolverUrl = getResolverUrl(envKey);
53
- this.loadersByDomain = {};
54
- this.retryConfig = {
55
- retries: 2
56
- };
57
- this.resolvedCache = {};
58
- }
59
-
60
- createLoader() {
61
- const batchResolveThrottler = pThrottle({
62
- limit: 1,
63
- interval: MIN_TIME_BETWEEN_BATCHES
64
- });
65
- const throttledBatchResolve = batchResolveThrottler(this.batchResolve);
66
- return new DataLoader( // We place all calls to `batchResolve` in a limiter so we don't send off several simultaneous batch requests.
67
- // This is for two reasons:
68
- // 1: we want to avoid getting rate limited upstream (eg: forge and other APIs)
69
- // 2: we want to avoid sending out heaps of requests from the client at once
70
- urls => throttledBatchResolve(urls), {
71
- maxBatchSize: MAX_BATCH_SIZE,
72
- // NOTE: we turn off DataLoader's cache because it doesn't work for our use-case. Consider the following:
73
- // - a smartlink to a restricted item is resolved to "forbidden" with a "request access button"
74
- // - the user clicks "request access", and then following the auth prompts and gets access
75
- // - the frontend now re-renders the smartlink, but due to DataLoader's caching, the previous "forbidden" state is
76
- // because the smartlink's URL (which is the cache key) is exactly the same
77
- //
78
- // For this reason, we disable DataLoader's cache.
79
- // This means that URLs will not be de-duplicated by DataLoader, so we perform the de-duplication logic
80
- // ourselves in `this.batchResolve`.
81
- cache: false
82
- });
83
- }
84
-
85
- getLoader(hostname) {
86
- if (!this.loadersByDomain[hostname]) {
87
- this.loadersByDomain[hostname] = this.createLoader();
88
- }
89
-
90
- return this.loadersByDomain[hostname];
91
- }
92
-
93
- async prefetchData(url) {
94
- // 1. Queue the URL as part of a dataloader batch.
95
- const hostname = new URL(url).hostname;
96
- const loader = this.getLoader(hostname);
97
- const response = await loader.load(url);
98
-
99
- if (isSuccessfulResponse(response)) {
100
- // 2. If the URL resolves, send it back.
101
- return response.body;
102
- } else {
103
- try {
104
- // 3. If the URL does not resolve, retry it with exponential backoff.
105
- // This is done so that we avoid the scenario where users are unable to
106
- // see a resolved Smart Link, when their expectation is to be able to.
107
- const retriedResponse = await retry(async () => {
108
- // We check if the link has resolved in the cache and stop trying if so.
109
- // We do this by triggering an error that the link has already been resolved.
110
- // This cascades <retryCount> times after which it is handled like a normal
111
- // 'error', returning `undefined`.
112
- if (!this.resolvedCache[url]) {
113
- const response = await loader.load(url);
114
-
115
- if (isSuccessfulResponse(response)) {
116
- return response;
117
- } else {
118
- throw new Error('Retry for URL failed');
119
- }
120
- } else {
121
- // Short-circuit each of the retries, as described above.
122
- throw new Error('Retry unneeded - link has been resolved.');
123
- }
124
- }, this.retryConfig); // Trigger callback after successful backoff.
125
-
126
- return retriedResponse.body;
127
- } catch (err) {
128
- // Do nothing in the case of an error - prefetching
129
- // failures should be silent. Once a link is visible,
130
- // it will be re-fetched anyhow, in which case a
131
- // user-facing error is required.
132
- return undefined;
133
- }
134
- }
135
- }
136
-
137
- async fetchData(url) {
138
- const hostname = new URL(url).hostname;
139
- const loader = this.getLoader(hostname);
140
- const response = await loader.load(url);
141
-
142
- if (!isSuccessfulResponse(response)) {
143
- // Catch non-200 server responses to fallback or return useful information.
144
- if (response.error) {
145
- const errorType = response.error.type;
146
- const errorMessage = response.error.message; // this means there was a network error and we fallback to blue link
147
- // without impacting SLO's
148
-
149
- if (response.error instanceof api.NetworkError) {
150
- throw new APIError('fallback', hostname, errorMessage, errorType);
151
- }
152
-
153
- switch (errorType) {
154
- // BadRequestError - indicative of an API error, render
155
- // a blue link to mitigate customer impact.
156
- case 'ResolveBadRequestError':
157
- throw new APIError('fallback', hostname, errorMessage, errorType);
158
- // AuthError - if the user logs in, we may be able
159
- // to recover. Render an unauthorized card.
160
-
161
- case 'ResolveAuthError':
162
- throw new APIError('auth', hostname, errorMessage, errorType);
163
- // UnsupportedError - we do not know how to render this URL.
164
- // Bail out and ask the Editor to render as a blue link.
165
-
166
- case 'ResolveUnsupportedError':
167
- // URL isn't supported
168
- throw new APIError('fatal', hostname, errorMessage, errorType);
169
- // ResolveFailedError - link resolver may have failed.
170
- // We could recover on re-resolve; render with fallback state.
171
-
172
- case 'ResolveFailedError':
173
- // Timeouts
174
- throw new APIError('error', hostname, errorMessage, errorType);
175
- // TimeoutError - link resolver may be taking a long time.
176
- // We could recover on re-resolve; render with fallback state.
177
-
178
- case 'ResolveTimeoutError':
179
- // Timeouts
180
- throw new APIError('error', hostname, errorMessage, errorType);
181
- // InternalServerError - API call failed.
182
- // We may recover later; render with fallback state.
183
-
184
- case 'InternalServerError':
185
- // ORS failures
186
- throw new APIError('error', hostname, errorMessage, errorType);
187
- }
188
- } // Catch all: we don't know this error, bail out.
189
-
190
-
191
- throw new APIError('fatal', hostname, response.toString(), 'UnexpectedError');
192
- } else {
193
- // Set a flag in the `resolvedCache` for this URL. The intent of this is
194
- // to ensure that the exponential backoff method in `prefetchData` does
195
- // not continue to retry fetching for this URL, especially if it was previously
196
- // in a failed state. Note: this scenario only occurs on initial page load, if the
197
- // user scrolls through the page very fast. Once the URL is visible, prefetching
198
- // no longer takes place.
199
- this.resolvedCache[url] = true; // Return the JSON-LD response back up!
200
-
201
- return response.body;
202
- }
203
- }
204
-
205
- async postData(data) {
206
- const request = {
207
- key: data.key,
208
- action: data.action,
209
- context: data.context
210
- };
211
- return await api.request('post', `${this.resolverUrl}/invoke`, request);
212
- }
213
-
214
- }
1
+ export { CardClient as default } from '@atlaskit/link-provider';
@@ -109,9 +109,6 @@ export let ElementName;
109
109
  ElementName["AuthorGroup"] = "AuthorGroup";
110
110
  ElementName["CollaboratorGroup"] = "CollaboratorGroup";
111
111
  ElementName["CommentCount"] = "CommentCount";
112
- ElementName["ViewCount"] = "ViewCount";
113
- ElementName["ReactCount"] = "ReactCount";
114
- ElementName["VoteCount"] = "VoteCount";
115
112
  ElementName["CreatedBy"] = "CreatedBy";
116
113
  ElementName["CreatedOn"] = "CreatedOn";
117
114
  ElementName["LinkIcon"] = "LinkIcon";
@@ -120,11 +117,14 @@ export let ElementName;
120
117
  ElementName["Preview"] = "Preview";
121
118
  ElementName["Priority"] = "Priority";
122
119
  ElementName["ProgrammingLanguage"] = "ProgrammingLanguage";
120
+ ElementName["Provider"] = "Provider";
121
+ ElementName["ReactCount"] = "ReactCount";
123
122
  ElementName["Snippet"] = "Snippet";
124
123
  ElementName["State"] = "State";
125
124
  ElementName["SubscriberCount"] = "SubscriberCount";
126
125
  ElementName["Title"] = "Title";
127
- ElementName["Provider"] = "Provider";
126
+ ElementName["ViewCount"] = "ViewCount";
127
+ ElementName["VoteCount"] = "VoteCount";
128
128
  })(ElementName || (ElementName = {}));
129
129
 
130
130
  export let ActionName;
@@ -1,6 +1,6 @@
1
- import { extractPreview } from '@atlaskit/linking-common';
2
1
  import { extractLink, extractTitle } from '../common/primitives';
3
2
  import { extractProvider } from '../common/context';
3
+ import { extractPreview } from '@atlaskit/linking-common';
4
4
  import { extractIsTrusted } from '../common/meta/extractIsTrusted';
5
5
 
6
6
  const extractEmbedPreview = (jsonLd, platform) => {
@@ -0,0 +1,18 @@
1
+ import { ElementName } from '../../constants';
2
+
3
+ const elementNamesToItems = elementNames => {
4
+ return elementNames.filter(element => element in ElementName).map(elementName => ({
5
+ name: elementName,
6
+ testId: `${elementName.toLowerCase()}-metadata-element`
7
+ }));
8
+ };
9
+
10
+ export const extractMetadata = jsonLd => {
11
+ var _jsonLd$metadata, _metadata$primary, _metadata$secondary;
12
+
13
+ const metadata = (_jsonLd$metadata = jsonLd.metadata) !== null && _jsonLd$metadata !== void 0 ? _jsonLd$metadata : [];
14
+ return {
15
+ primary: elementNamesToItems((_metadata$primary = metadata.primary) !== null && _metadata$primary !== void 0 ? _metadata$primary : []),
16
+ secondary: elementNamesToItems((_metadata$secondary = metadata.secondary) !== null && _metadata$secondary !== void 0 ? _metadata$secondary : [])
17
+ };
18
+ };
@@ -1,9 +1,9 @@
1
1
  export { SmartCardProvider as Provider, SmartCardContext } from './state';
2
- export { EditorCardProvider, editorCardProvider } from './providers/editor';
3
- export { default as Client } from './client';
4
- export { APIError } from './client/errors';
2
+ export { EditorCardProvider, editorCardProvider } from '@atlaskit/link-provider';
3
+ export { APIError } from '@atlaskit/linking-common';
4
+ export { CardClient as Client } from '@atlaskit/link-provider';
5
5
  export { Card } from './view/Card';
6
- export { default as Context } from './state/context';
6
+ export { SmartCardContext as Context } from '@atlaskit/link-provider';
7
7
  export { EmbedResizeMessageListener } from './view/EmbedCard/EmbedResizeMessageListener';
8
8
  export { embedHeaderHeight } from './view/EmbedCard/components/styled';
9
9
  export { SmartLinkEvents } from './utils/analytics/analytics';
@@ -1,9 +1,3 @@
1
- export const ACTION_PENDING = 'pending';
2
- export const ACTION_RESOLVING = 'resolving';
3
- export const ACTION_RESOLVED = 'resolved';
4
- export const ACTION_ERROR = 'errored';
5
- export const ACTION_ERROR_FALLBACK = 'fallback';
6
- export const ACTION_PRELOAD = 'preload';
7
1
  export const ANALYTICS_RESOLVING = 'resolving';
8
2
  export const ANALYTICS_ERROR = 'errored';
9
3
  export const ANALYTICS_FALLBACK = 'fallback';
@@ -1,11 +1,11 @@
1
1
  import { useMemo, useCallback } from 'react';
2
2
  import { auth } from '@atlaskit/outbound-auth-flow-client';
3
- import { cardAction } from './helpers';
3
+ import { APIError } from '@atlaskit/linking-common';
4
+ import { useSmartLinkContext } from '@atlaskit/link-provider';
5
+ import { ACTION_PENDING, ACTION_RESOLVED, ACTION_ERROR, ACTION_ERROR_FALLBACK, cardAction } from '@atlaskit/linking-common';
4
6
  import { getDefinitionId, getByDefinitionId, getServices, getStatus, getExtensionKey } from '../helpers';
5
- import { ACTION_PENDING, ACTION_RESOLVED, ACTION_ERROR, ERROR_MESSAGE_OAUTH, ERROR_MESSAGE_FATAL, ACTION_ERROR_FALLBACK } from './constants';
6
- import { useSmartLinkContext } from '../context';
7
+ import { ERROR_MESSAGE_OAUTH, ERROR_MESSAGE_FATAL } from './constants';
7
8
  import * as measure from '../../utils/performance';
8
- import { APIError } from '../../client/errors';
9
9
  import { getUnauthorizedJsonLd } from '../../utils/jsonld';
10
10
  import { addMetadataToExperience } from '../analytics';
11
11
  export const useSmartCardActions = (id, url, analytics) => {
@@ -1,5 +1,5 @@
1
- import { uiAuthEvent, uiAuthAlternateAccountEvent, uiCardClickedEvent, uiActionClickedEvent, uiClosedAuthEvent, uiRenderSuccessEvent, uiHoverCardViewedEvent, uiHoverCardDismissedEvent, uiHoverCardOpenLinkClickedEvent, resolvedEvent, unresolvedEvent, invokeSucceededEvent, invokeFailedEvent, connectSucceededEvent, connectFailedEvent, trackAppAccountConnected, screenAuthPopupEvent, instrumentEvent } from '../../utils/analytics';
2
1
  import { useMemo } from 'react';
2
+ import { uiAuthEvent, uiAuthAlternateAccountEvent, uiCardClickedEvent, uiActionClickedEvent, uiClosedAuthEvent, uiRenderSuccessEvent, uiHoverCardViewedEvent, uiHoverCardDismissedEvent, uiHoverCardOpenLinkClickedEvent, resolvedEvent, unresolvedEvent, invokeSucceededEvent, invokeFailedEvent, connectSucceededEvent, connectFailedEvent, trackAppAccountConnected, screenAuthPopupEvent, instrumentEvent } from '../../utils/analytics';
3
3
  import { failUfoExperience, startUfoExperience, succeedUfoExperience } from './ufoExperiences';
4
4
  export const useSmartLinkAnalytics = dispatchAnalytics => {
5
5
  const ui = useMemo(() => ({
@@ -1,4 +1,4 @@
1
- import { useSmartLinkContext } from '../context';
1
+ import { useSmartLinkContext } from '@atlaskit/link-provider';
2
2
  export const useSmartLinkConfig = () => {
3
3
  const context = useSmartLinkContext();
4
4
 
@@ -8,11 +8,6 @@ export const getByDefinitionId = (definitionId, store) => {
8
8
  return details && details.meta.definitionId === definitionId;
9
9
  });
10
10
  };
11
- export const getUrl = (store, url) => {
12
- return store.getState()[url] || {
13
- status: 'pending'
14
- };
15
- };
16
11
  export const getClickUrl = (url, jsonLd) => {
17
12
  if (jsonLd && jsonLd.data) {
18
13
  const visitUrl = extractVisitUrl(jsonLd.data);
@@ -1,5 +1,5 @@
1
1
  import { useCallback } from 'react';
2
- import { useSmartLinkContext } from '../context';
2
+ import { useSmartLinkContext } from '@atlaskit/link-provider';
3
3
  export function usePrefetch(url) {
4
4
  const {
5
5
  store,
@@ -1,2 +1,2 @@
1
- export { SmartCardContext, SmartCardProvider, useSmartLinkContext } from './context';
1
+ export { SmartCardContext, SmartCardProvider, useSmartLinkContext } from '@atlaskit/link-provider';
2
2
  export { useSmartLink, usePrefetch } from './hooks';
@@ -1,5 +1,5 @@
1
1
  import { useMemo } from 'react';
2
- import { useSmartLinkContext } from '../context';
2
+ import { useSmartLinkContext } from '@atlaskit/link-provider';
3
3
  export const useSmartLinkRenderers = () => {
4
4
  const context = useSmartLinkContext();
5
5
  let renderers = context === null || context === void 0 ? void 0 : context.renderers;
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useState } from 'react';
2
- import { useSmartLinkContext } from '../context';
3
- import { getUrl } from '../helpers';
2
+ import { useSmartLinkContext } from '@atlaskit/link-provider';
3
+ import { getUrl } from '@atlaskit/linking-common';
4
4
  export function useSmartCardState(url) {
5
5
  const {
6
6
  store
@@ -1,4 +1,4 @@
1
- import CardClient from '../client';
1
+ import { CardClient } from '@atlaskit/link-provider';
2
2
  export const mockContext = {
3
3
  '@vocab': 'https://www.w3.org/ns/activitystreams#',
4
4
  atlassian: 'https://schema.atlassian.com/ns/vocabulary#',
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React from 'react';
3
- import CardClient from '../client';
3
+ import { CardClient } from '@atlaskit/link-provider';
4
4
  import { SmartCardProvider } from '../state';
5
5
 
6
6
  const Hook = props => {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "18.0.21",
3
+ "version": "19.0.1",
4
4
  "sideEffects": false
5
5
  }
@@ -84,8 +84,8 @@ export const sizeToSpacing = {
84
84
  [SmartLinkSize.XLarge]: 'default'
85
85
  };
86
86
  /**
87
- * An action that can be triggered with an on click.
88
- * @public
87
+ * A base action that can be triggered with an on click.
88
+ * @internal
89
89
  * @param {ActionProps} ActionProps - The props necessary for the Action.
90
90
  * @see DeleteAction
91
91
  * @see EditAction
@@ -29,6 +29,7 @@ const styles = css`
29
29
  /**
30
30
  * Creates a group of Action components. Accepts an array of Actions, in addition to some styling
31
31
  * preferences.
32
+ * @internal
32
33
  * @param {ActionGroupProps} ActionGroupProps
33
34
  * @see Action
34
35
  */
@@ -13,8 +13,9 @@ const getBlockStyles = (direction, size) => css`
13
13
  }
14
14
  `;
15
15
  /**
16
- * A block represents a collection of elements and actions that are arranged in a row.
17
- * All elements and actions should be contained within a Block.
16
+ * A block represents a collection of elements and actions that are arranged
17
+ * in a row. All elements and actions should be contained within a Block.
18
+ * @internal
18
19
  * @param {ActionGroupProps} ActionGroupProps
19
20
  * @see Action
20
21
  */
@@ -30,6 +30,7 @@ export const getElementGroupStyles = (direction, size, align, width) => css`
30
30
  /**
31
31
  * Creates a group of Action components. Accepts an array of Actions, in addition to some styling
32
32
  * preferences.
33
+ * @internal
33
34
  * @param {ActionGroupProps} ActionGroupProps
34
35
  * @see Action
35
36
  */
@@ -8,6 +8,7 @@ import ActionGroup from '../action-group';
8
8
  /**
9
9
  * Represents a FooterBlock, designed to contain elements and actions that should appear
10
10
  * at the bottom of a link card.
11
+ * @public
11
12
  * @param {FooterBlockProps} FooterBlockProps
12
13
  * @see Block
13
14
  */
@@ -63,6 +63,7 @@ const getMaxLines = maxLines => {
63
63
  /**
64
64
  * Represents a MetadataBlock, designed to contain groups of metadata in the form of elements.
65
65
  * Accepts an array of elements to be shown either primary (left hand side) or secondary (right hand side).
66
+ * @public
66
67
  * @param {MetadataBlockProps} MetadataBlockProps
67
68
  * @see Block
68
69
  */
@@ -5,6 +5,7 @@ import Block from '../block';
5
5
  import { Preview } from '../../elements';
6
6
  /**
7
7
  * Represents a PreviewBlock, which typically contains media or other large format content.
8
+ * @public
8
9
  * @param {PreviewBlock} PreviewBlock
9
10
  * @see Block
10
11
  */
@@ -9,6 +9,7 @@ const MAXIMUM_MAX_LINES = 3;
9
9
  const MINIMUM_MAX_LINES = 1;
10
10
  /**
11
11
  * Represents a SnippetBlock, which is used to display longer form text content, like descriptions.
12
+ * @public
12
13
  * @param {SnippetBlock} SnippetBlock
13
14
  * @see Block
14
15
  */
@@ -42,10 +42,11 @@ const getTitleBlockViewComponent = status => {
42
42
  }
43
43
  };
44
44
  /**
45
- * Represents a TitleBlock, which is the foundation of all Flexible Smart Links.
45
+ * Represents a TitleBlock, which is the foundation of Flexible UI.
46
46
  * This contains an icon, the link, and any associated metadata and actions in one block.
47
47
  * The TitleBlock will also render differently given the state of the smart link.
48
48
  * This can be found in the corresponding Resolving, Resolved and Errored views.
49
+ * @public
49
50
  * @param {TitleBlockProps} TitleBlockProps
50
51
  * @see Block
51
52
  * @see TitleBlockResolvingView
@@ -81,12 +81,21 @@ const renderChildren = (children, containerSize, containerTheme, status, retry,
81
81
  const {
82
82
  size: blockSize
83
83
  } = child.props;
84
+ const size = blockSize || containerSize;
85
+
86
+ if (isFlexibleUiTitleBlock(child)) {
87
+ return /*#__PURE__*/React.cloneElement(child, {
88
+ onClick,
89
+ retry,
90
+ size,
91
+ status,
92
+ theme: containerTheme
93
+ });
94
+ }
95
+
84
96
  return /*#__PURE__*/React.cloneElement(child, {
85
- onClick,
86
- retry: isFlexibleUiTitleBlock(child) ? retry : undefined,
87
- size: blockSize || containerSize,
88
- status,
89
- theme: containerTheme
97
+ size,
98
+ status
90
99
  });
91
100
  }
92
101
  });
@@ -116,7 +125,11 @@ const getLayeredLink = (testId, context, children) => {
116
125
  });
117
126
  };
118
127
  /**
119
- * This represents the container in which all Flexible UI Smart Links are rendered.
128
+ * A container is a hidden component that build the Flexible Smart Link.
129
+ * All of the Flexible UI components are wrapped inside the container.
130
+ * It inherits the ui props from Card component and applies the custom styling
131
+ * accordingly.
132
+ * @internal
120
133
  * @see Block
121
134
  */
122
135
 
@@ -35,6 +35,11 @@ const styles = css`
35
35
  }
36
36
  }
37
37
  `;
38
+ /**
39
+ * An anchor component to cover the entire container creating a clickable area.
40
+ * @internal
41
+ * @see `clickableContainer`
42
+ */
38
43
 
39
44
  const LayeredLink = ({
40
45
  target,
@@ -27,8 +27,8 @@ const getStyles = size => {
27
27
  }
28
28
  };
29
29
  /**
30
- * An element that displays a group of avatars.
31
- * @public
30
+ * A base element that displays a group of avatars.
31
+ * @internal
32
32
  * @param {AvatarGroupProps} AvatarGroupProps - The props necessary for the AvatarGroup.
33
33
  * @see AuthorGroup
34
34
  * @see CollaboratorGroup
@@ -71,8 +71,8 @@ const renderImageIcon = (url, testId) => {
71
71
  }
72
72
  };
73
73
  /**
74
- * An element that displays some text with an associated icon.
75
- * @public
74
+ * A base element that displays some text with an associated icon.
75
+ * @internal
76
76
  * @param {BadgeProps} BadgeProps - The props necessary for the Badge.
77
77
  * @see CommentCount
78
78
  * @see ViewCount
@@ -19,8 +19,8 @@ const typeToDescriptorMap = {
19
19
  modified: messages.modified_on
20
20
  };
21
21
  /**
22
- * An element that displays an ISO Timestamp in text.
23
- * @public
22
+ * A base element that displays an ISO Timestamp in text.
23
+ * @internal
24
24
  * @param {DateTimeProps} DateTimeProps - The props necessary for the DateTime element.
25
25
  * @see CreatedOn
26
26
  * @see ModifiedOn
@@ -67,8 +67,8 @@ const renderImageIcon = (defaultIcon, icon, url, testId) => {
67
67
  }
68
68
  };
69
69
  /**
70
- * An element that displays an Icon or favicon.
71
- * @public
70
+ * A base element that displays an Icon or favicon.
71
+ * @internal
72
72
  * @param {IconProps} IconProps - The props necessary for the Icon element.
73
73
  * @see LinkIcon
74
74
  */
@@ -5,12 +5,12 @@ import { ElementName } from '../../../../constants';
5
5
  // createElement and renderElementItems
6
6
 
7
7
  /**
8
- * Creates an AvatarGroup element using the data from AuthorGroup in the Flexible UI Context.
8
+ * An AvatarGroup element using the data from AuthorGroup in the Flexible UI Context.
9
9
  * @see AvatarGroup
10
10
  */
11
11
  export const AuthorGroup = createElement(ElementName.AuthorGroup);
12
12
  /**
13
- * Creates an AvatarGroup element using the data from CollaboratorGroup in the Flexible UI Context.
13
+ * An AvatarGroup element using the data from CollaboratorGroup in the Flexible UI Context.
14
14
  * @see AvatarGroup
15
15
  */
16
16