@atlaskit/editor-card-provider 6.8.23 → 7.0.0

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,39 @@
1
1
  # @atlaskit/editor-card-provider
2
2
 
3
+ ## 7.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [`f2dc9097319f0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f2dc9097319f0) - ###
8
+ Dropped support for _legacy_ Typescript 4 types. **Typescript 5 is now the new minimum**.
9
+
10
+ Removes the `typesVersions` property and `dist/types-ts4.5` directory from the dist.
11
+
12
+ Types are now exclusively via the `"types": "dist/types/index.d.ts"` property.
13
+
14
+ ```diff
15
+ - "typesVersions": {
16
+ - ">=4.5 <4.9": {
17
+ - "*": [
18
+ - "dist/types-ts4.5/*",
19
+ - "dist/types-ts4.5/index.d.ts"
20
+ - ]
21
+ - }
22
+ - },
23
+ ```
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies
28
+
29
+ ## 6.8.24
30
+
31
+ ### Patch Changes
32
+
33
+ - [`027beb2f61316`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/027beb2f61316) -
34
+ Update smart link appearance, if and only if smart link is created from confluence editor quick
35
+ insert menu
36
+
3
37
  ## 6.8.23
4
38
 
5
39
  ### Patch Changes
@@ -698,7 +698,23 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function (_No
698
698
  return _canBeResolvedAsEmbed.apply(this, arguments);
699
699
  }
700
700
  return canBeResolvedAsEmbed;
701
- }())
701
+ }()
702
+ /**
703
+ * Opt-in hook: when a caller explicitly requests an `'embed'` appearance and the
704
+ * user has no saved preference for the URL, honour that request as the default
705
+ * (above any provider default), validating embeddability first and falling back
706
+ * to a card (`'block'`) when the link cannot be embedded.
707
+ *
708
+ * Defaults to `false` so behaviour is unchanged for every existing consumer.
709
+ * Subclasses (e.g. Confluence) can override this to opt in, typically behind an
710
+ * experiment.
711
+ */
712
+ )
713
+ }, {
714
+ key: "shouldHonorRequestedEmbedAsDefault",
715
+ value: function shouldHonorRequestedEmbedAsDefault() {
716
+ return false;
717
+ }
702
718
  }, {
703
719
  key: "getAuthStatusFromResolveResponse",
704
720
  value: function () {
@@ -787,7 +803,7 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function (_No
787
803
  key: "resolve",
788
804
  value: function () {
789
805
  var _resolve = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(url, appearance, shouldForceAppearance, isEmbedFriendlyLocation) {
790
- var hardCodedAppearance, _yield$Promise$all, _yield$Promise$all2, matchedProviderPattern, userPreference, data, issueAri, _this$onResolve, isSupported, providerDefaultAppearance, isEmbedFriendlyLocationEvaluated, preferredAppearance, canItBeEmbed, datasource, id, parameters, authStatus, access, _t8, _t9;
806
+ var hardCodedAppearance, _yield$Promise$all, _yield$Promise$all2, matchedProviderPattern, userPreference, data, issueAri, _this$onResolve, isSupported, providerDefaultAppearance, isEmbedFriendlyLocationEvaluated, preferredAppearance, canItBeEmbed, _canItBeEmbed, datasource, id, parameters, authStatus, access, _t8, _t9;
791
807
  return _regenerator.default.wrap(function (_context11) {
792
808
  while (1) switch (_context11.prev = _context11.next) {
793
809
  case 0:
@@ -843,7 +859,7 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function (_No
843
859
  case 7:
844
860
  isSupported = _t8;
845
861
  if (!isSupported) {
846
- _context11.next = 14;
862
+ _context11.next = 16;
847
863
  break;
848
864
  }
849
865
  providerDefaultAppearance = matchedProviderPattern === null || matchedProviderPattern === void 0 ? void 0 : matchedProviderPattern.defaultView;
@@ -873,12 +889,22 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function (_No
873
889
  preferredAppearance = 'inline';
874
890
  }
875
891
  case 9:
892
+ if (!(!userPreference && appearance === 'embed' && isEmbedFriendlyLocationEvaluated && this.shouldHonorRequestedEmbedAsDefault())) {
893
+ _context11.next = 11;
894
+ break;
895
+ }
876
896
  _context11.next = 10;
877
- return this.getDatasourceFromResolveResponse(url);
897
+ return this.canBeResolvedAsEmbed(url);
878
898
  case 10:
899
+ _canItBeEmbed = _context11.sent;
900
+ preferredAppearance = _canItBeEmbed ? 'embed' : 'block';
901
+ case 11:
902
+ _context11.next = 12;
903
+ return this.getDatasourceFromResolveResponse(url);
904
+ case 12:
879
905
  datasource = _context11.sent;
880
906
  if (!datasource) {
881
- _context11.next = 11;
907
+ _context11.next = 13;
882
908
  break;
883
909
  }
884
910
  id = datasource.id, parameters = datasource.parameters;
@@ -891,42 +917,42 @@ var EditorCardProvider = exports.EditorCardProvider = /*#__PURE__*/function (_No
891
917
  type: 'table'
892
918
  }]
893
919
  }, url));
894
- case 11:
920
+ case 13:
895
921
  if (!(isEmbedFriendlyLocationEvaluated && !userPreference)) {
896
- _context11.next = 13;
922
+ _context11.next = 15;
897
923
  break;
898
924
  }
899
- _context11.next = 12;
925
+ _context11.next = 14;
900
926
  return this.getAuthStatusFromResolveResponse(url);
901
- case 12:
927
+ case 14:
902
928
  authStatus = _context11.sent;
903
929
  if (!authStatus) {
904
- _context11.next = 13;
930
+ _context11.next = 15;
905
931
  break;
906
932
  }
907
933
  access = authStatus.access;
908
934
  if (!(access === 'unauthorized')) {
909
- _context11.next = 13;
935
+ _context11.next = 15;
910
936
  break;
911
937
  }
912
938
  return _context11.abrupt("return", this.transformer.toSmartlinkAdf(url, 'block'));
913
- case 13:
939
+ case 15:
914
940
  return _context11.abrupt("return", this.transformer.toSmartlinkAdf(url, preferredAppearance));
915
- case 14:
916
- _context11.next = 16;
941
+ case 16:
942
+ _context11.next = 18;
917
943
  break;
918
- case 15:
919
- _context11.prev = 15;
944
+ case 17:
945
+ _context11.prev = 17;
920
946
  _t9 = _context11["catch"](0);
921
947
  // eslint-disable-next-line
922
948
  console.warn("Error when trying to check Smart Card url \"".concat(url, "\"").concat(_t9 instanceof Error ? " - ".concat(_t9.name, " ").concat(_t9.message) : ''), _t9);
923
- case 16:
949
+ case 18:
924
950
  return _context11.abrupt("return", Promise.reject(undefined));
925
- case 17:
951
+ case 19:
926
952
  case "end":
927
953
  return _context11.stop();
928
954
  }
929
- }, _callee11, this, [[0, 15]]);
955
+ }, _callee11, this, [[0, 17]]);
930
956
  }));
931
957
  function resolve(_x1, _x10, _x11, _x12) {
932
958
  return _resolve.apply(this, arguments);
@@ -362,6 +362,20 @@ export class EditorCardProvider extends NodeDataProvider {
362
362
  return false;
363
363
  }
364
364
  }
365
+
366
+ /**
367
+ * Opt-in hook: when a caller explicitly requests an `'embed'` appearance and the
368
+ * user has no saved preference for the URL, honour that request as the default
369
+ * (above any provider default), validating embeddability first and falling back
370
+ * to a card (`'block'`) when the link cannot be embedded.
371
+ *
372
+ * Defaults to `false` so behaviour is unchanged for every existing consumer.
373
+ * Subclasses (e.g. Confluence) can override this to opt in, typically behind an
374
+ * experiment.
375
+ */
376
+ shouldHonorRequestedEmbedAsDefault() {
377
+ return false;
378
+ }
365
379
  async getAuthStatusFromResolveResponse(url) {
366
380
  try {
367
381
  const {
@@ -450,6 +464,17 @@ export class EditorCardProvider extends NodeDataProvider {
450
464
  preferredAppearance = 'inline';
451
465
  }
452
466
  }
467
+
468
+ // When a caller explicitly requested an embed (e.g. Confluence's quick-insert
469
+ // embed flow tags the inserted link) and the user has no saved preference for
470
+ // this URL, honour embed-by-default above the provider default — but only in an
471
+ // embed-friendly location (matching how hard-coded embeds are gated above) and
472
+ // only when the link can actually be embedded, otherwise fall back to a card.
473
+ // Gated behind a default-off opt-in hook so other consumers are unaffected.
474
+ if (!userPreference && appearance === 'embed' && isEmbedFriendlyLocationEvaluated && this.shouldHonorRequestedEmbedAsDefault()) {
475
+ const canItBeEmbed = await this.canBeResolvedAsEmbed(url);
476
+ preferredAppearance = canItBeEmbed ? 'embed' : 'block';
477
+ }
453
478
  const datasource = await this.getDatasourceFromResolveResponse(url);
454
479
  if (datasource) {
455
480
  const {
@@ -690,7 +690,23 @@ export var EditorCardProvider = /*#__PURE__*/function (_NodeDataProvider) {
690
690
  return _canBeResolvedAsEmbed.apply(this, arguments);
691
691
  }
692
692
  return canBeResolvedAsEmbed;
693
- }())
693
+ }()
694
+ /**
695
+ * Opt-in hook: when a caller explicitly requests an `'embed'` appearance and the
696
+ * user has no saved preference for the URL, honour that request as the default
697
+ * (above any provider default), validating embeddability first and falling back
698
+ * to a card (`'block'`) when the link cannot be embedded.
699
+ *
700
+ * Defaults to `false` so behaviour is unchanged for every existing consumer.
701
+ * Subclasses (e.g. Confluence) can override this to opt in, typically behind an
702
+ * experiment.
703
+ */
704
+ )
705
+ }, {
706
+ key: "shouldHonorRequestedEmbedAsDefault",
707
+ value: function shouldHonorRequestedEmbedAsDefault() {
708
+ return false;
709
+ }
694
710
  }, {
695
711
  key: "getAuthStatusFromResolveResponse",
696
712
  value: function () {
@@ -779,7 +795,7 @@ export var EditorCardProvider = /*#__PURE__*/function (_NodeDataProvider) {
779
795
  key: "resolve",
780
796
  value: function () {
781
797
  var _resolve = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(url, appearance, shouldForceAppearance, isEmbedFriendlyLocation) {
782
- var hardCodedAppearance, _yield$Promise$all, _yield$Promise$all2, matchedProviderPattern, userPreference, data, issueAri, _this$onResolve, isSupported, providerDefaultAppearance, isEmbedFriendlyLocationEvaluated, preferredAppearance, canItBeEmbed, datasource, id, parameters, authStatus, access, _t8, _t9;
798
+ var hardCodedAppearance, _yield$Promise$all, _yield$Promise$all2, matchedProviderPattern, userPreference, data, issueAri, _this$onResolve, isSupported, providerDefaultAppearance, isEmbedFriendlyLocationEvaluated, preferredAppearance, canItBeEmbed, _canItBeEmbed, datasource, id, parameters, authStatus, access, _t8, _t9;
783
799
  return _regeneratorRuntime.wrap(function (_context11) {
784
800
  while (1) switch (_context11.prev = _context11.next) {
785
801
  case 0:
@@ -835,7 +851,7 @@ export var EditorCardProvider = /*#__PURE__*/function (_NodeDataProvider) {
835
851
  case 7:
836
852
  isSupported = _t8;
837
853
  if (!isSupported) {
838
- _context11.next = 14;
854
+ _context11.next = 16;
839
855
  break;
840
856
  }
841
857
  providerDefaultAppearance = matchedProviderPattern === null || matchedProviderPattern === void 0 ? void 0 : matchedProviderPattern.defaultView;
@@ -865,12 +881,22 @@ export var EditorCardProvider = /*#__PURE__*/function (_NodeDataProvider) {
865
881
  preferredAppearance = 'inline';
866
882
  }
867
883
  case 9:
884
+ if (!(!userPreference && appearance === 'embed' && isEmbedFriendlyLocationEvaluated && this.shouldHonorRequestedEmbedAsDefault())) {
885
+ _context11.next = 11;
886
+ break;
887
+ }
868
888
  _context11.next = 10;
869
- return this.getDatasourceFromResolveResponse(url);
889
+ return this.canBeResolvedAsEmbed(url);
870
890
  case 10:
891
+ _canItBeEmbed = _context11.sent;
892
+ preferredAppearance = _canItBeEmbed ? 'embed' : 'block';
893
+ case 11:
894
+ _context11.next = 12;
895
+ return this.getDatasourceFromResolveResponse(url);
896
+ case 12:
871
897
  datasource = _context11.sent;
872
898
  if (!datasource) {
873
- _context11.next = 11;
899
+ _context11.next = 13;
874
900
  break;
875
901
  }
876
902
  id = datasource.id, parameters = datasource.parameters;
@@ -883,42 +909,42 @@ export var EditorCardProvider = /*#__PURE__*/function (_NodeDataProvider) {
883
909
  type: 'table'
884
910
  }]
885
911
  }, url));
886
- case 11:
912
+ case 13:
887
913
  if (!(isEmbedFriendlyLocationEvaluated && !userPreference)) {
888
- _context11.next = 13;
914
+ _context11.next = 15;
889
915
  break;
890
916
  }
891
- _context11.next = 12;
917
+ _context11.next = 14;
892
918
  return this.getAuthStatusFromResolveResponse(url);
893
- case 12:
919
+ case 14:
894
920
  authStatus = _context11.sent;
895
921
  if (!authStatus) {
896
- _context11.next = 13;
922
+ _context11.next = 15;
897
923
  break;
898
924
  }
899
925
  access = authStatus.access;
900
926
  if (!(access === 'unauthorized')) {
901
- _context11.next = 13;
927
+ _context11.next = 15;
902
928
  break;
903
929
  }
904
930
  return _context11.abrupt("return", this.transformer.toSmartlinkAdf(url, 'block'));
905
- case 13:
931
+ case 15:
906
932
  return _context11.abrupt("return", this.transformer.toSmartlinkAdf(url, preferredAppearance));
907
- case 14:
908
- _context11.next = 16;
933
+ case 16:
934
+ _context11.next = 18;
909
935
  break;
910
- case 15:
911
- _context11.prev = 15;
936
+ case 17:
937
+ _context11.prev = 17;
912
938
  _t9 = _context11["catch"](0);
913
939
  // eslint-disable-next-line
914
940
  console.warn("Error when trying to check Smart Card url \"".concat(url, "\"").concat(_t9 instanceof Error ? " - ".concat(_t9.name, " ").concat(_t9.message) : ''), _t9);
915
- case 16:
941
+ case 18:
916
942
  return _context11.abrupt("return", Promise.reject(undefined));
917
- case 17:
943
+ case 19:
918
944
  case "end":
919
945
  return _context11.stop();
920
946
  }
921
- }, _callee11, this, [[0, 15]]);
947
+ }, _callee11, this, [[0, 17]]);
922
948
  }));
923
949
  function resolve(_x1, _x10, _x11, _x12) {
924
950
  return _resolve.apply(this, arguments);
@@ -65,6 +65,17 @@ export declare class EditorCardProvider extends NodeDataProvider<CardNode, JsonL
65
65
  * Make a /resolve call and find out if result has embed capability
66
66
  */
67
67
  private canBeResolvedAsEmbed;
68
+ /**
69
+ * Opt-in hook: when a caller explicitly requests an `'embed'` appearance and the
70
+ * user has no saved preference for the URL, honour that request as the default
71
+ * (above any provider default), validating embeddability first and falling back
72
+ * to a card (`'block'`) when the link cannot be embedded.
73
+ *
74
+ * Defaults to `false` so behaviour is unchanged for every existing consumer.
75
+ * Subclasses (e.g. Confluence) can override this to opt in, typically behind an
76
+ * experiment.
77
+ */
78
+ protected shouldHonorRequestedEmbedAsDefault(): boolean;
68
79
  private getAuthStatusFromResolveResponse;
69
80
  /**
70
81
  * Make a /resolve call and find out if result has datasource capability
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-card-provider",
3
- "version": "6.8.23",
3
+ "version": "7.0.0",
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",
@@ -18,33 +18,25 @@
18
18
  "module": "dist/esm/index.js",
19
19
  "module:es2019": "dist/es2019/index.js",
20
20
  "types": "dist/types/index.d.ts",
21
- "typesVersions": {
22
- ">=4.5 <4.9": {
23
- "*": [
24
- "dist/types-ts4.5/*",
25
- "dist/types-ts4.5/index.d.ts"
26
- ]
27
- }
28
- },
29
21
  "sideEffects": false,
30
22
  "atlaskit:src": "src/index.ts",
31
23
  "dependencies": {
32
- "@atlaskit/editor-json-transformer": "^8.33.0",
33
- "@atlaskit/feature-gate-js-client": "^5.8.0",
34
- "@atlaskit/frontend-utilities": "^3.4.0",
35
- "@atlaskit/json-ld-types": "^1.5.0",
36
- "@atlaskit/link-client-extension": "^6.1.0",
37
- "@atlaskit/link-extractors": "^2.7.0",
38
- "@atlaskit/linking-common": "^9.13.0",
39
- "@atlaskit/linking-types": "^14.4.0",
40
- "@atlaskit/node-data-provider": "^12.0.0",
41
- "@atlaskit/platform-feature-flags": "^1.1.0",
42
- "@atlaskit/tmp-editor-statsig": "^103.0.0",
24
+ "@atlaskit/editor-json-transformer": "^9.0.0",
25
+ "@atlaskit/feature-gate-js-client": "^6.0.0",
26
+ "@atlaskit/frontend-utilities": "^4.0.0",
27
+ "@atlaskit/json-ld-types": "^2.0.0",
28
+ "@atlaskit/link-client-extension": "^7.0.0",
29
+ "@atlaskit/link-extractors": "^3.0.0",
30
+ "@atlaskit/linking-common": "^10.0.0",
31
+ "@atlaskit/linking-types": "^15.0.0",
32
+ "@atlaskit/node-data-provider": "^13.0.0",
33
+ "@atlaskit/platform-feature-flags": "^2.0.0",
34
+ "@atlaskit/tmp-editor-statsig": "^104.0.0",
43
35
  "@babel/runtime": "^7.0.0",
44
36
  "dataloader": "^2.1.0"
45
37
  },
46
38
  "peerDependencies": {
47
- "@atlaskit/link-provider": "^4.7.0",
39
+ "@atlaskit/link-provider": "^5.0.0",
48
40
  "react": "^18.2.0"
49
41
  },
50
42
  "devDependencies": {