@atlaskit/editor-card-provider 3.0.5 → 3.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/editor-card-provider
2
2
 
3
+ ## 3.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`1e7190077d4`](https://bitbucket.org/atlassian/atlassian-frontend/commits/1e7190077d4) - Move off deprecated @atlaskit/linking-common/extractors to @atlaskit/link-extractors
8
+ - Updated dependencies
9
+
10
+ ## 3.1.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [`04295e9d5bc`](https://bitbucket.org/atlassian/atlassian-frontend/commits/04295e9d5bc) - [ux] Updating ORS response to include datasources and facilitating pasting JQL links turning into datasource tables
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies
19
+
3
20
  ## 3.0.5
4
21
 
5
22
  ### Patch Changes
@@ -15,7 +15,7 @@ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits
15
15
  var _setPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/setPrototypeOf"));
16
16
  require("setimmediate");
17
17
  var _dataloader = _interopRequireDefault(require("dataloader"));
18
- var _linkingCommon = require("@atlaskit/linking-common");
18
+ var _linkExtractors = require("@atlaskit/link-extractors");
19
19
  var _transformer = require("./transformer");
20
20
  var _environments = require("./environments");
21
21
  var _utils = require("./utils");
@@ -97,9 +97,9 @@ var EditorCardProvider = /*#__PURE__*/function () {
97
97
  return batchProviders;
98
98
  }()
99
99
  }, {
100
- key: "check",
100
+ key: "checkLinkResolved",
101
101
  value: function () {
102
- var _check = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resourceUrl) {
102
+ var _checkLinkResolved = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resourceUrl) {
103
103
  var response;
104
104
  return _regenerator.default.wrap(function _callee2$(_context2) {
105
105
  while (1) switch (_context2.prev = _context2.next) {
@@ -127,10 +127,10 @@ var EditorCardProvider = /*#__PURE__*/function () {
127
127
  }
128
128
  }, _callee2, this, [[0, 8]]);
129
129
  }));
130
- function check(_x2) {
131
- return _check.apply(this, arguments);
130
+ function checkLinkResolved(_x2) {
131
+ return _checkLinkResolved.apply(this, arguments);
132
132
  }
133
- return check;
133
+ return checkLinkResolved;
134
134
  }()
135
135
  }, {
136
136
  key: "fetchProvidersData",
@@ -210,7 +210,7 @@ var EditorCardProvider = /*#__PURE__*/function () {
210
210
  break;
211
211
  }
212
212
  _context5.next = 6;
213
- return this.check(url);
213
+ return this.checkLinkResolved(url);
214
214
  case 6:
215
215
  _context5.t0 = !!_context5.sent;
216
216
  case 7:
@@ -327,8 +327,6 @@ var EditorCardProvider = /*#__PURE__*/function () {
327
327
 
328
328
  /**
329
329
  * Make a /resolve call and find out if result has embed capability
330
- * @param url
331
- * @private
332
330
  */
333
331
  }, {
334
332
  key: "canBeResolvedAsEmbed",
@@ -356,7 +354,7 @@ var EditorCardProvider = /*#__PURE__*/function () {
356
354
  }
357
355
  return _context8.abrupt("return", false);
358
356
  case 9:
359
- preview = (0, _linkingCommon.extractPreview)(data, 'web');
357
+ preview = (0, _linkExtractors.extractPreview)(data, 'web');
360
358
  return _context8.abrupt("return", !!preview);
361
359
  case 13:
362
360
  _context8.prev = 13;
@@ -373,48 +371,88 @@ var EditorCardProvider = /*#__PURE__*/function () {
373
371
  }
374
372
  return canBeResolvedAsEmbed;
375
373
  }()
374
+ /**
375
+ * Make a /resolve call and find out if result has datasource capability
376
+ */
376
377
  }, {
377
- key: "resolve",
378
+ key: "getDatasourceFromResolveResponse",
378
379
  value: function () {
379
- var _resolve = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(url, appearance, shouldForceAppearance) {
380
- var hardCodedAppearance, _yield$Promise$all, _yield$Promise$all2, matchedProviderPattern, userPreference, isSupported, providerDefaultAppearance, preferredAppearance, canItBeEmbed;
380
+ var _getDatasourceFromResolveResponse = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(url) {
381
+ var response, datasources;
381
382
  return _regenerator.default.wrap(function _callee9$(_context9) {
382
383
  while (1) switch (_context9.prev = _context9.next) {
383
384
  case 0:
384
385
  _context9.prev = 0;
386
+ _context9.next = 3;
387
+ return this.cardClient.fetchData(url);
388
+ case 3:
389
+ response = _context9.sent;
390
+ datasources = response && response.datasources || [];
391
+ if (!(datasources.length > 0)) {
392
+ _context9.next = 7;
393
+ break;
394
+ }
395
+ return _context9.abrupt("return", datasources[0]);
396
+ case 7:
397
+ _context9.next = 12;
398
+ break;
399
+ case 9:
400
+ _context9.prev = 9;
401
+ _context9.t0 = _context9["catch"](0);
402
+ return _context9.abrupt("return", undefined);
403
+ case 12:
404
+ case "end":
405
+ return _context9.stop();
406
+ }
407
+ }, _callee9, this, [[0, 9]]);
408
+ }));
409
+ function getDatasourceFromResolveResponse(_x7) {
410
+ return _getDatasourceFromResolveResponse.apply(this, arguments);
411
+ }
412
+ return getDatasourceFromResolveResponse;
413
+ }()
414
+ }, {
415
+ key: "resolve",
416
+ value: function () {
417
+ var _resolve = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(url, appearance, shouldForceAppearance) {
418
+ var hardCodedAppearance, _yield$Promise$all, _yield$Promise$all2, matchedProviderPattern, userPreference, isSupported, providerDefaultAppearance, preferredAppearance, canItBeEmbed, datasource, id, parameters;
419
+ return _regenerator.default.wrap(function _callee10$(_context10) {
420
+ while (1) switch (_context10.prev = _context10.next) {
421
+ case 0:
422
+ _context10.prev = 0;
385
423
  if (!(shouldForceAppearance === true)) {
386
- _context9.next = 3;
424
+ _context10.next = 3;
387
425
  break;
388
426
  }
389
- return _context9.abrupt("return", this.transformer.toAdf(url, appearance));
427
+ return _context10.abrupt("return", this.transformer.toSmartlinkAdf(url, appearance));
390
428
  case 3:
391
429
  hardCodedAppearance = this.getHardCodedAppearance(url);
392
- _context9.next = 6;
430
+ _context10.next = 6;
393
431
  return Promise.all([this.findPatternData(url), this.findUserPreference(url)]);
394
432
  case 6:
395
- _yield$Promise$all = _context9.sent;
433
+ _yield$Promise$all = _context10.sent;
396
434
  _yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 2);
397
435
  matchedProviderPattern = _yield$Promise$all2[0];
398
436
  userPreference = _yield$Promise$all2[1];
399
437
  if (!(shouldForceAppearance === false && userPreference === 'url')) {
400
- _context9.next = 12;
438
+ _context10.next = 12;
401
439
  break;
402
440
  }
403
- return _context9.abrupt("return", Promise.reject(undefined));
441
+ return _context10.abrupt("return", Promise.reject(undefined));
404
442
  case 12:
405
- _context9.t0 = !!matchedProviderPattern;
406
- if (_context9.t0) {
407
- _context9.next = 17;
443
+ _context10.t0 = !!matchedProviderPattern;
444
+ if (_context10.t0) {
445
+ _context10.next = 17;
408
446
  break;
409
447
  }
410
- _context9.next = 16;
411
- return this.check(url);
448
+ _context10.next = 16;
449
+ return this.checkLinkResolved(url);
412
450
  case 16:
413
- _context9.t0 = _context9.sent;
451
+ _context10.t0 = _context10.sent;
414
452
  case 17:
415
- isSupported = _context9.t0;
453
+ isSupported = _context10.t0;
416
454
  if (!isSupported) {
417
- _context9.next = 27;
455
+ _context10.next = 33;
418
456
  break;
419
457
  }
420
458
  providerDefaultAppearance = matchedProviderPattern === null || matchedProviderPattern === void 0 ? void 0 : matchedProviderPattern.defaultView;
@@ -432,35 +470,54 @@ var EditorCardProvider = /*#__PURE__*/function () {
432
470
  // If not, we pick what editor (or any other client) requested
433
471
  appearance;
434
472
  if (!(preferredAppearance === userPreference && userPreference === 'embed')) {
435
- _context9.next = 26;
473
+ _context10.next = 26;
436
474
  break;
437
475
  }
438
- _context9.next = 24;
476
+ _context10.next = 24;
439
477
  return this.canBeResolvedAsEmbed(url);
440
478
  case 24:
441
- canItBeEmbed = _context9.sent;
479
+ canItBeEmbed = _context10.sent;
442
480
  if (!canItBeEmbed) {
443
481
  preferredAppearance = 'inline';
444
482
  }
445
483
  case 26:
446
- return _context9.abrupt("return", this.transformer.toAdf(url, preferredAppearance));
447
- case 27:
448
- _context9.next = 32;
449
- break;
450
- case 29:
451
- _context9.prev = 29;
452
- _context9.t1 = _context9["catch"](0);
453
- // eslint-disable-next-line
454
- console.warn("Error when trying to check Smart Card url \"".concat(url, "\"").concat(_context9.t1 instanceof Error ? " - ".concat(_context9.t1.name, " ").concat(_context9.t1.message) : ''), _context9.t1);
484
+ _context10.next = 28;
485
+ return this.getDatasourceFromResolveResponse(url);
486
+ case 28:
487
+ datasource = _context10.sent;
488
+ if (!datasource) {
489
+ _context10.next = 32;
490
+ break;
491
+ }
492
+ id = datasource.id, parameters = datasource.parameters;
493
+ return _context10.abrupt("return", this.transformer.toDatasourceAdf({
494
+ id: id,
495
+ parameters: parameters,
496
+ // in the future when we support multiple views, we will need to pass this in as a parameter
497
+ // transform toDatasourceAdf to accept multiple views (like how how appearance for other other transforms are handled)
498
+ views: [{
499
+ type: 'table'
500
+ }]
501
+ }, url));
455
502
  case 32:
456
- return _context9.abrupt("return", Promise.reject(undefined));
503
+ return _context10.abrupt("return", this.transformer.toSmartlinkAdf(url, preferredAppearance));
457
504
  case 33:
505
+ _context10.next = 38;
506
+ break;
507
+ case 35:
508
+ _context10.prev = 35;
509
+ _context10.t1 = _context10["catch"](0);
510
+ // eslint-disable-next-line
511
+ console.warn("Error when trying to check Smart Card url \"".concat(url, "\"").concat(_context10.t1 instanceof Error ? " - ".concat(_context10.t1.name, " ").concat(_context10.t1.message) : ''), _context10.t1);
512
+ case 38:
513
+ return _context10.abrupt("return", Promise.reject(undefined));
514
+ case 39:
458
515
  case "end":
459
- return _context9.stop();
516
+ return _context10.stop();
460
517
  }
461
- }, _callee9, this, [[0, 29]]);
518
+ }, _callee10, this, [[0, 35]]);
462
519
  }));
463
- function resolve(_x7, _x8, _x9) {
520
+ function resolve(_x8, _x9, _x10) {
464
521
  return _resolve.apply(this, arguments);
465
522
  }
466
523
  return resolve;
@@ -43,8 +43,19 @@ var Transformer = /*#__PURE__*/function () {
43
43
  };
44
44
  }
45
45
  }, {
46
- key: "toAdf",
47
- value: function toAdf(url, appearance) {
46
+ key: "buildDatasourceAdf",
47
+ value: function buildDatasourceAdf(datasource, url) {
48
+ return {
49
+ type: 'blockCard',
50
+ attrs: {
51
+ url: url,
52
+ datasource: datasource
53
+ }
54
+ };
55
+ }
56
+ }, {
57
+ key: "toSmartlinkAdf",
58
+ value: function toSmartlinkAdf(url, appearance) {
48
59
  switch (appearance) {
49
60
  case 'inline':
50
61
  return this.buildInlineAdf(url);
@@ -54,6 +65,11 @@ var Transformer = /*#__PURE__*/function () {
54
65
  return this.buildEmbedAdf(url);
55
66
  }
56
67
  }
68
+ }, {
69
+ key: "toDatasourceAdf",
70
+ value: function toDatasourceAdf(datasource, url) {
71
+ return this.buildDatasourceAdf(datasource, url);
72
+ }
57
73
  }]);
58
74
  return Transformer;
59
75
  }();
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-card-provider",
3
- "version": "3.0.5",
3
+ "version": "3.1.1",
4
4
  "sideEffects": false
5
5
  }
@@ -2,7 +2,7 @@
2
2
  // @see https://github.com/graphql/dataloader/issues/249
3
3
  import 'setimmediate';
4
4
  import DataLoader from 'dataloader';
5
- import { extractPreview } from '@atlaskit/linking-common';
5
+ import { extractPreview } from '@atlaskit/link-extractors';
6
6
  import { Transformer } from './transformer';
7
7
  import { getBaseUrl, getResolverUrl } from './environments';
8
8
  import { getStatus } from './utils';
@@ -37,7 +37,7 @@ export class EditorCardProvider {
37
37
  const providersData = await this.fetchProvidersData();
38
38
  return keys.map(() => providersData);
39
39
  }
40
- async check(resourceUrl) {
40
+ async checkLinkResolved(resourceUrl) {
41
41
  try {
42
42
  const response = await this.cardClient.fetchData(resourceUrl);
43
43
  if (getStatus(response) !== 'not_found') {
@@ -68,7 +68,7 @@ export class EditorCardProvider {
68
68
  }
69
69
  }
70
70
  async findPattern(url) {
71
- return !!(await this.findPatternData(url)) || !!(await this.check(url));
71
+ return !!(await this.findPatternData(url)) || !!(await this.checkLinkResolved(url));
72
72
  }
73
73
  doesUrlMatchPath(path, url) {
74
74
  // Using [a-zA-Z0-9] here instead of \w since that includes underscores
@@ -116,8 +116,6 @@ export class EditorCardProvider {
116
116
 
117
117
  /**
118
118
  * Make a /resolve call and find out if result has embed capability
119
- * @param url
120
- * @private
121
119
  */
122
120
  async canBeResolvedAsEmbed(url) {
123
121
  try {
@@ -139,20 +137,37 @@ export class EditorCardProvider {
139
137
  return false;
140
138
  }
141
139
  }
140
+
141
+ /**
142
+ * Make a /resolve call and find out if result has datasource capability
143
+ */
144
+ async getDatasourceFromResolveResponse(url) {
145
+ try {
146
+ const response = await this.cardClient.fetchData(url);
147
+ const datasources = response && response.datasources || [];
148
+ if (datasources.length > 0) {
149
+ // For now we only have one datasource expected even though it is in an array.
150
+ // When we have resources returning more than one we will have revisit this part.
151
+ return datasources[0];
152
+ }
153
+ } catch (e) {
154
+ return undefined;
155
+ }
156
+ }
142
157
  async resolve(url, appearance, shouldForceAppearance) {
143
158
  try {
144
159
  if (shouldForceAppearance === true) {
145
160
  // At this point we don't need to check pattern nor call `check` because manual change means
146
161
  // this url is already supported and can be resolved. We want to ignore all other options and
147
162
  // respect user's choice.
148
- return this.transformer.toAdf(url, appearance);
163
+ return this.transformer.toSmartlinkAdf(url, appearance);
149
164
  }
150
165
  const hardCodedAppearance = this.getHardCodedAppearance(url);
151
166
  const [matchedProviderPattern, userPreference] = await Promise.all([this.findPatternData(url), this.findUserPreference(url)]);
152
167
  if (shouldForceAppearance === false && userPreference === 'url') {
153
168
  return Promise.reject(undefined);
154
169
  }
155
- let isSupported = !!matchedProviderPattern || (await this.check(url));
170
+ let isSupported = !!matchedProviderPattern || (await this.checkLinkResolved(url));
156
171
  if (isSupported) {
157
172
  const providerDefaultAppearance = matchedProviderPattern === null || matchedProviderPattern === void 0 ? void 0 : matchedProviderPattern.defaultView;
158
173
  let preferredAppearance = shouldForceAppearance === undefined ?
@@ -174,7 +189,23 @@ export class EditorCardProvider {
174
189
  preferredAppearance = 'inline';
175
190
  }
176
191
  }
177
- return this.transformer.toAdf(url, preferredAppearance);
192
+ const datasource = await this.getDatasourceFromResolveResponse(url);
193
+ if (datasource) {
194
+ const {
195
+ id,
196
+ parameters
197
+ } = datasource;
198
+ return this.transformer.toDatasourceAdf({
199
+ id,
200
+ parameters,
201
+ // in the future when we support multiple views, we will need to pass this in as a parameter
202
+ // transform toDatasourceAdf to accept multiple views (like how how appearance for other other transforms are handled)
203
+ views: [{
204
+ type: 'table'
205
+ }]
206
+ }, url);
207
+ }
208
+ return this.transformer.toSmartlinkAdf(url, preferredAppearance);
178
209
  }
179
210
  } catch (e) {
180
211
  // eslint-disable-next-line
@@ -24,7 +24,16 @@ export class Transformer {
24
24
  }
25
25
  };
26
26
  }
27
- toAdf(url, appearance) {
27
+ buildDatasourceAdf(datasource, url) {
28
+ return {
29
+ type: 'blockCard',
30
+ attrs: {
31
+ url,
32
+ datasource
33
+ }
34
+ };
35
+ }
36
+ toSmartlinkAdf(url, appearance) {
28
37
  switch (appearance) {
29
38
  case 'inline':
30
39
  return this.buildInlineAdf(url);
@@ -34,4 +43,7 @@ export class Transformer {
34
43
  return this.buildEmbedAdf(url);
35
44
  }
36
45
  }
46
+ toDatasourceAdf(datasource, url) {
47
+ return this.buildDatasourceAdf(datasource, url);
48
+ }
37
49
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-card-provider",
3
- "version": "3.0.5",
3
+ "version": "3.1.1",
4
4
  "sideEffects": false
5
5
  }
@@ -11,7 +11,7 @@ function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return
11
11
  // @see https://github.com/graphql/dataloader/issues/249
12
12
  import 'setimmediate';
13
13
  import DataLoader from 'dataloader';
14
- import { extractPreview } from '@atlaskit/linking-common';
14
+ import { extractPreview } from '@atlaskit/link-extractors';
15
15
  import { Transformer } from './transformer';
16
16
  import { getBaseUrl, getResolverUrl } from './environments';
17
17
  import { getStatus } from './utils';
@@ -89,9 +89,9 @@ export var EditorCardProvider = /*#__PURE__*/function () {
89
89
  return batchProviders;
90
90
  }()
91
91
  }, {
92
- key: "check",
92
+ key: "checkLinkResolved",
93
93
  value: function () {
94
- var _check = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resourceUrl) {
94
+ var _checkLinkResolved = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resourceUrl) {
95
95
  var response;
96
96
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
97
97
  while (1) switch (_context2.prev = _context2.next) {
@@ -119,10 +119,10 @@ export var EditorCardProvider = /*#__PURE__*/function () {
119
119
  }
120
120
  }, _callee2, this, [[0, 8]]);
121
121
  }));
122
- function check(_x2) {
123
- return _check.apply(this, arguments);
122
+ function checkLinkResolved(_x2) {
123
+ return _checkLinkResolved.apply(this, arguments);
124
124
  }
125
- return check;
125
+ return checkLinkResolved;
126
126
  }()
127
127
  }, {
128
128
  key: "fetchProvidersData",
@@ -202,7 +202,7 @@ export var EditorCardProvider = /*#__PURE__*/function () {
202
202
  break;
203
203
  }
204
204
  _context5.next = 6;
205
- return this.check(url);
205
+ return this.checkLinkResolved(url);
206
206
  case 6:
207
207
  _context5.t0 = !!_context5.sent;
208
208
  case 7:
@@ -319,8 +319,6 @@ export var EditorCardProvider = /*#__PURE__*/function () {
319
319
 
320
320
  /**
321
321
  * Make a /resolve call and find out if result has embed capability
322
- * @param url
323
- * @private
324
322
  */
325
323
  }, {
326
324
  key: "canBeResolvedAsEmbed",
@@ -365,48 +363,88 @@ export var EditorCardProvider = /*#__PURE__*/function () {
365
363
  }
366
364
  return canBeResolvedAsEmbed;
367
365
  }()
366
+ /**
367
+ * Make a /resolve call and find out if result has datasource capability
368
+ */
368
369
  }, {
369
- key: "resolve",
370
+ key: "getDatasourceFromResolveResponse",
370
371
  value: function () {
371
- var _resolve = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(url, appearance, shouldForceAppearance) {
372
- var hardCodedAppearance, _yield$Promise$all, _yield$Promise$all2, matchedProviderPattern, userPreference, isSupported, providerDefaultAppearance, preferredAppearance, canItBeEmbed;
372
+ var _getDatasourceFromResolveResponse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(url) {
373
+ var response, datasources;
373
374
  return _regeneratorRuntime.wrap(function _callee9$(_context9) {
374
375
  while (1) switch (_context9.prev = _context9.next) {
375
376
  case 0:
376
377
  _context9.prev = 0;
378
+ _context9.next = 3;
379
+ return this.cardClient.fetchData(url);
380
+ case 3:
381
+ response = _context9.sent;
382
+ datasources = response && response.datasources || [];
383
+ if (!(datasources.length > 0)) {
384
+ _context9.next = 7;
385
+ break;
386
+ }
387
+ return _context9.abrupt("return", datasources[0]);
388
+ case 7:
389
+ _context9.next = 12;
390
+ break;
391
+ case 9:
392
+ _context9.prev = 9;
393
+ _context9.t0 = _context9["catch"](0);
394
+ return _context9.abrupt("return", undefined);
395
+ case 12:
396
+ case "end":
397
+ return _context9.stop();
398
+ }
399
+ }, _callee9, this, [[0, 9]]);
400
+ }));
401
+ function getDatasourceFromResolveResponse(_x7) {
402
+ return _getDatasourceFromResolveResponse.apply(this, arguments);
403
+ }
404
+ return getDatasourceFromResolveResponse;
405
+ }()
406
+ }, {
407
+ key: "resolve",
408
+ value: function () {
409
+ var _resolve = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(url, appearance, shouldForceAppearance) {
410
+ var hardCodedAppearance, _yield$Promise$all, _yield$Promise$all2, matchedProviderPattern, userPreference, isSupported, providerDefaultAppearance, preferredAppearance, canItBeEmbed, datasource, id, parameters;
411
+ return _regeneratorRuntime.wrap(function _callee10$(_context10) {
412
+ while (1) switch (_context10.prev = _context10.next) {
413
+ case 0:
414
+ _context10.prev = 0;
377
415
  if (!(shouldForceAppearance === true)) {
378
- _context9.next = 3;
416
+ _context10.next = 3;
379
417
  break;
380
418
  }
381
- return _context9.abrupt("return", this.transformer.toAdf(url, appearance));
419
+ return _context10.abrupt("return", this.transformer.toSmartlinkAdf(url, appearance));
382
420
  case 3:
383
421
  hardCodedAppearance = this.getHardCodedAppearance(url);
384
- _context9.next = 6;
422
+ _context10.next = 6;
385
423
  return Promise.all([this.findPatternData(url), this.findUserPreference(url)]);
386
424
  case 6:
387
- _yield$Promise$all = _context9.sent;
425
+ _yield$Promise$all = _context10.sent;
388
426
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
389
427
  matchedProviderPattern = _yield$Promise$all2[0];
390
428
  userPreference = _yield$Promise$all2[1];
391
429
  if (!(shouldForceAppearance === false && userPreference === 'url')) {
392
- _context9.next = 12;
430
+ _context10.next = 12;
393
431
  break;
394
432
  }
395
- return _context9.abrupt("return", Promise.reject(undefined));
433
+ return _context10.abrupt("return", Promise.reject(undefined));
396
434
  case 12:
397
- _context9.t0 = !!matchedProviderPattern;
398
- if (_context9.t0) {
399
- _context9.next = 17;
435
+ _context10.t0 = !!matchedProviderPattern;
436
+ if (_context10.t0) {
437
+ _context10.next = 17;
400
438
  break;
401
439
  }
402
- _context9.next = 16;
403
- return this.check(url);
440
+ _context10.next = 16;
441
+ return this.checkLinkResolved(url);
404
442
  case 16:
405
- _context9.t0 = _context9.sent;
443
+ _context10.t0 = _context10.sent;
406
444
  case 17:
407
- isSupported = _context9.t0;
445
+ isSupported = _context10.t0;
408
446
  if (!isSupported) {
409
- _context9.next = 27;
447
+ _context10.next = 33;
410
448
  break;
411
449
  }
412
450
  providerDefaultAppearance = matchedProviderPattern === null || matchedProviderPattern === void 0 ? void 0 : matchedProviderPattern.defaultView;
@@ -424,35 +462,54 @@ export var EditorCardProvider = /*#__PURE__*/function () {
424
462
  // If not, we pick what editor (or any other client) requested
425
463
  appearance;
426
464
  if (!(preferredAppearance === userPreference && userPreference === 'embed')) {
427
- _context9.next = 26;
465
+ _context10.next = 26;
428
466
  break;
429
467
  }
430
- _context9.next = 24;
468
+ _context10.next = 24;
431
469
  return this.canBeResolvedAsEmbed(url);
432
470
  case 24:
433
- canItBeEmbed = _context9.sent;
471
+ canItBeEmbed = _context10.sent;
434
472
  if (!canItBeEmbed) {
435
473
  preferredAppearance = 'inline';
436
474
  }
437
475
  case 26:
438
- return _context9.abrupt("return", this.transformer.toAdf(url, preferredAppearance));
439
- case 27:
440
- _context9.next = 32;
441
- break;
442
- case 29:
443
- _context9.prev = 29;
444
- _context9.t1 = _context9["catch"](0);
445
- // eslint-disable-next-line
446
- console.warn("Error when trying to check Smart Card url \"".concat(url, "\"").concat(_context9.t1 instanceof Error ? " - ".concat(_context9.t1.name, " ").concat(_context9.t1.message) : ''), _context9.t1);
476
+ _context10.next = 28;
477
+ return this.getDatasourceFromResolveResponse(url);
478
+ case 28:
479
+ datasource = _context10.sent;
480
+ if (!datasource) {
481
+ _context10.next = 32;
482
+ break;
483
+ }
484
+ id = datasource.id, parameters = datasource.parameters;
485
+ return _context10.abrupt("return", this.transformer.toDatasourceAdf({
486
+ id: id,
487
+ parameters: parameters,
488
+ // in the future when we support multiple views, we will need to pass this in as a parameter
489
+ // transform toDatasourceAdf to accept multiple views (like how how appearance for other other transforms are handled)
490
+ views: [{
491
+ type: 'table'
492
+ }]
493
+ }, url));
447
494
  case 32:
448
- return _context9.abrupt("return", Promise.reject(undefined));
495
+ return _context10.abrupt("return", this.transformer.toSmartlinkAdf(url, preferredAppearance));
449
496
  case 33:
497
+ _context10.next = 38;
498
+ break;
499
+ case 35:
500
+ _context10.prev = 35;
501
+ _context10.t1 = _context10["catch"](0);
502
+ // eslint-disable-next-line
503
+ console.warn("Error when trying to check Smart Card url \"".concat(url, "\"").concat(_context10.t1 instanceof Error ? " - ".concat(_context10.t1.name, " ").concat(_context10.t1.message) : ''), _context10.t1);
504
+ case 38:
505
+ return _context10.abrupt("return", Promise.reject(undefined));
506
+ case 39:
450
507
  case "end":
451
- return _context9.stop();
508
+ return _context10.stop();
452
509
  }
453
- }, _callee9, this, [[0, 29]]);
510
+ }, _callee10, this, [[0, 35]]);
454
511
  }));
455
- function resolve(_x7, _x8, _x9) {
512
+ function resolve(_x8, _x9, _x10) {
456
513
  return _resolve.apply(this, arguments);
457
514
  }
458
515
  return resolve;
@@ -36,8 +36,19 @@ export var Transformer = /*#__PURE__*/function () {
36
36
  };
37
37
  }
38
38
  }, {
39
- key: "toAdf",
40
- value: function toAdf(url, appearance) {
39
+ key: "buildDatasourceAdf",
40
+ value: function buildDatasourceAdf(datasource, url) {
41
+ return {
42
+ type: 'blockCard',
43
+ attrs: {
44
+ url: url,
45
+ datasource: datasource
46
+ }
47
+ };
48
+ }
49
+ }, {
50
+ key: "toSmartlinkAdf",
51
+ value: function toSmartlinkAdf(url, appearance) {
41
52
  switch (appearance) {
42
53
  case 'inline':
43
54
  return this.buildInlineAdf(url);
@@ -47,6 +58,11 @@ export var Transformer = /*#__PURE__*/function () {
47
58
  return this.buildEmbedAdf(url);
48
59
  }
49
60
  }
61
+ }, {
62
+ key: "toDatasourceAdf",
63
+ value: function toDatasourceAdf(datasource, url) {
64
+ return this.buildDatasourceAdf(datasource, url);
65
+ }
50
66
  }]);
51
67
  return Transformer;
52
68
  }();
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-card-provider",
3
- "version": "3.0.5",
3
+ "version": "3.1.1",
4
4
  "sideEffects": false
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import 'setimmediate';
2
- import { CardAdf, CardAppearance } from '@atlaskit/linking-common';
2
+ import { CardAdf, CardAppearance, DatasourceAdf } from '@atlaskit/linking-common';
3
3
  import { CardProvider } from './types';
4
4
  import { EnvironmentsKeys } from './environments';
5
5
  export declare class EditorCardProvider implements CardProvider {
@@ -12,7 +12,7 @@ export declare class EditorCardProvider implements CardProvider {
12
12
  private cardClient;
13
13
  constructor(envKey?: EnvironmentsKeys, baseUrlOverride?: string);
14
14
  private batchProviders;
15
- private check;
15
+ private checkLinkResolved;
16
16
  private fetchProvidersData;
17
17
  private loadProviderData;
18
18
  findPattern(url: string): Promise<boolean>;
@@ -22,11 +22,13 @@ export declare class EditorCardProvider implements CardProvider {
22
22
  private getHardCodedAppearance;
23
23
  /**
24
24
  * Make a /resolve call and find out if result has embed capability
25
- * @param url
26
- * @private
27
25
  */
28
26
  private canBeResolvedAsEmbed;
29
- resolve(url: string, appearance: CardAppearance, shouldForceAppearance?: boolean): Promise<CardAdf>;
27
+ /**
28
+ * Make a /resolve call and find out if result has datasource capability
29
+ */
30
+ private getDatasourceFromResolveResponse;
31
+ resolve(url: string, appearance: CardAppearance, shouldForceAppearance?: boolean): Promise<CardAdf | DatasourceAdf>;
30
32
  }
31
33
  export declare const editorCardProvider: EditorCardProvider;
32
34
  export type { CardProvider } from './types';
@@ -1,7 +1,9 @@
1
- import { CardAppearance, CardAdf } from '@atlaskit/linking-common';
1
+ import { CardAppearance, CardAdf, DatasourceAdf, Datasource } from '@atlaskit/linking-common';
2
2
  export declare class Transformer {
3
3
  private buildInlineAdf;
4
4
  private buildBlockAdf;
5
5
  private buildEmbedAdf;
6
- toAdf(url: string, appearance: CardAppearance): CardAdf;
6
+ private buildDatasourceAdf;
7
+ toSmartlinkAdf(url: string, appearance: CardAppearance): CardAdf;
8
+ toDatasourceAdf(datasource: Datasource, url?: string): DatasourceAdf;
7
9
  }
@@ -1,5 +1,5 @@
1
1
  import 'setimmediate';
2
- import { CardAdf, CardAppearance } from '@atlaskit/linking-common';
2
+ import { CardAdf, CardAppearance, DatasourceAdf } from '@atlaskit/linking-common';
3
3
  import { CardProvider } from './types';
4
4
  import { EnvironmentsKeys } from './environments';
5
5
  export declare class EditorCardProvider implements CardProvider {
@@ -12,7 +12,7 @@ export declare class EditorCardProvider implements CardProvider {
12
12
  private cardClient;
13
13
  constructor(envKey?: EnvironmentsKeys, baseUrlOverride?: string);
14
14
  private batchProviders;
15
- private check;
15
+ private checkLinkResolved;
16
16
  private fetchProvidersData;
17
17
  private loadProviderData;
18
18
  findPattern(url: string): Promise<boolean>;
@@ -22,11 +22,13 @@ export declare class EditorCardProvider implements CardProvider {
22
22
  private getHardCodedAppearance;
23
23
  /**
24
24
  * Make a /resolve call and find out if result has embed capability
25
- * @param url
26
- * @private
27
25
  */
28
26
  private canBeResolvedAsEmbed;
29
- resolve(url: string, appearance: CardAppearance, shouldForceAppearance?: boolean): Promise<CardAdf>;
27
+ /**
28
+ * Make a /resolve call and find out if result has datasource capability
29
+ */
30
+ private getDatasourceFromResolveResponse;
31
+ resolve(url: string, appearance: CardAppearance, shouldForceAppearance?: boolean): Promise<CardAdf | DatasourceAdf>;
30
32
  }
31
33
  export declare const editorCardProvider: EditorCardProvider;
32
34
  export type { CardProvider } from './types';
@@ -1,7 +1,9 @@
1
- import { CardAppearance, CardAdf } from '@atlaskit/linking-common';
1
+ import { CardAppearance, CardAdf, DatasourceAdf, Datasource } from '@atlaskit/linking-common';
2
2
  export declare class Transformer {
3
3
  private buildInlineAdf;
4
4
  private buildBlockAdf;
5
5
  private buildEmbedAdf;
6
- toAdf(url: string, appearance: CardAppearance): CardAdf;
6
+ private buildDatasourceAdf;
7
+ toSmartlinkAdf(url: string, appearance: CardAppearance): CardAdf;
8
+ toDatasourceAdf(datasource: Datasource, url?: string): DatasourceAdf;
7
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-card-provider",
3
- "version": "3.0.5",
3
+ "version": "3.1.1",
4
4
  "description": "Contains the EditorCardProvider, for determining smart card behaviour in the editor.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,7 +34,9 @@
34
34
  ".": "./src/index.ts"
35
35
  },
36
36
  "dependencies": {
37
- "@atlaskit/linking-common": "^3.0.0",
37
+ "@atlaskit/link-client-extension": "^1.5.0",
38
+ "@atlaskit/link-extractors": "^1.1.0",
39
+ "@atlaskit/linking-common": "^3.2.0",
38
40
  "@babel/runtime": "^7.0.0",
39
41
  "dataloader": "^2.0.0",
40
42
  "json-ld-types": "3.7.0",
package/report.api.md CHANGED
@@ -17,6 +17,7 @@
17
17
  ```ts
18
18
  import { CardAdf } from '@atlaskit/linking-common';
19
19
  import { CardAppearance } from '@atlaskit/linking-common';
20
+ import { DatasourceAdf } from '@atlaskit/linking-common';
20
21
 
21
22
  // @public (undocumented)
22
23
  const BaseUrls: {
@@ -49,7 +50,7 @@ export class EditorCardProvider implements CardProvider {
49
50
  url: string,
50
51
  appearance: CardAppearance,
51
52
  shouldForceAppearance?: boolean,
52
- ): Promise<CardAdf>;
53
+ ): Promise<CardAdf | DatasourceAdf>;
53
54
  }
54
55
 
55
56
  // @public (undocumented)
@@ -6,6 +6,7 @@
6
6
 
7
7
  import { CardAdf } from '@atlaskit/linking-common';
8
8
  import { CardAppearance } from '@atlaskit/linking-common';
9
+ import { DatasourceAdf } from '@atlaskit/linking-common';
9
10
 
10
11
  // @public (undocumented)
11
12
  const BaseUrls: {
@@ -30,7 +31,7 @@ export class EditorCardProvider implements CardProvider {
30
31
  // (undocumented)
31
32
  findPattern(url: string): Promise<boolean>;
32
33
  // (undocumented)
33
- resolve(url: string, appearance: CardAppearance, shouldForceAppearance?: boolean): Promise<CardAdf>;
34
+ resolve(url: string, appearance: CardAppearance, shouldForceAppearance?: boolean): Promise<CardAdf | DatasourceAdf>;
34
35
  }
35
36
 
36
37
  // @public (undocumented)