@atlaskit/editor-plugin-card 16.1.0 → 16.3.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,38 @@
1
1
  # @atlaskit/editor-plugin-card
2
2
 
3
+ ## 16.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`85699a44bd1f8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/85699a44bd1f8) -
8
+ Add Confluence short-link URL expansion for native embeds. When a Confluence short link
9
+ (`/wiki/x/<token>`) is pasted, it is resolved to its canonical page URL via the Object Resolver
10
+ Service before matching against registered experience manifests, gated behind
11
+ `platform-native-embeds-short-link-expansion`.
12
+ - `NativeEmbedFacade`: new `expandShortLink`, `getExperienceIdFromUrlAsync`, and `setCardClient`
13
+ methods; `createExperienceForUrl` now expands short links before manifest matching.
14
+ - `editor-plugin-card`: exposes `resolveShortLinkUrl` action; `replaceQueuedUrlWithCard` supports
15
+ async `EmbedCardNodeTransformer` return values.
16
+ - `editor-plugin-native-embeds`: wires `cardClient` from config and passes `api` to
17
+ `cardToNativeEmbedNode` for async short-link resolution.
18
+ - `editor-common`: `EmbedCardNodeTransformer` type updated to allow `Promise` return;
19
+ `CardPluginActions` extended with `resolveShortLinkUrl`.
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies
24
+
25
+ ## 16.2.0
26
+
27
+ ### Minor Changes
28
+
29
+ - [`e5cdd96dcf4f9`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e5cdd96dcf4f9) -
30
+ Clean up platform_editor_hydratable_ui experiment (shipped as enabled)
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies
35
+
3
36
  ## 16.1.0
4
37
 
5
38
  ### Minor Changes
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.cardPlugin = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
11
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
12
  var _react = _interopRequireDefault(require("react"));
@@ -173,6 +174,89 @@ var cardPlugin = exports.cardPlugin = function cardPlugin(_ref) {
173
174
  registerEmbedCardTransformer: function registerEmbedCardTransformer(transformers) {
174
175
  instanceEmbedCardTransformers = transformers;
175
176
  },
177
+ resolveShortLinkUrl: function () {
178
+ var _resolveShortLinkUrl = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(url) {
179
+ var provider, clientHolder, client, response, data, urlField, _linkObj$Id, linkObj, id;
180
+ return _regenerator.default.wrap(function _callee2$(_context2) {
181
+ while (1) switch (_context2.prev = _context2.next) {
182
+ case 0:
183
+ if (options.provider) {
184
+ _context2.next = 2;
185
+ break;
186
+ }
187
+ return _context2.abrupt("return", undefined);
188
+ case 2:
189
+ _context2.prev = 2;
190
+ _context2.next = 5;
191
+ return options.provider;
192
+ case 5:
193
+ provider = _context2.sent;
194
+ // EditorCardProvider holds a CardClient instance internally. We access it
195
+ // directly to call fetchData, which gives us the raw ORS JSON-LD response
196
+ // including the canonical url field — something provider.resolve() does not
197
+ // surface. This is intentionally a structural cast rather than a typed
198
+ // dependency on EditorCardProvider's private API.
199
+ clientHolder = provider;
200
+ client = clientHolder.cardClient;
201
+ if (client) {
202
+ _context2.next = 10;
203
+ break;
204
+ }
205
+ return _context2.abrupt("return", undefined);
206
+ case 10:
207
+ _context2.next = 12;
208
+ return client.fetchData(url);
209
+ case 12:
210
+ response = _context2.sent;
211
+ // ORS returns a JsonLd.Response whose data union includes BaseData,
212
+ // BaseCollectionData, and BaseCollectionPage. We only care about the
213
+ // `url` field which is present on BaseData (Primitives.Object). Cast
214
+ // to a minimal shape rather than accessing through the full union type.
215
+ data = response === null || response === void 0 ? void 0 : response.data;
216
+ if (data) {
217
+ _context2.next = 16;
218
+ break;
219
+ }
220
+ return _context2.abrupt("return", undefined);
221
+ case 16:
222
+ urlField = data.url; // Property<string | Link> can be a string, a Link object, or an array.
223
+ // Short-link responses always return a plain string URL.
224
+ if (!(typeof urlField === 'string' && urlField !== url)) {
225
+ _context2.next = 19;
226
+ break;
227
+ }
228
+ return _context2.abrupt("return", urlField);
229
+ case 19:
230
+ if (!(urlField && (0, _typeof2.default)(urlField) === 'object' && !Array.isArray(urlField))) {
231
+ _context2.next = 24;
232
+ break;
233
+ }
234
+ linkObj = urlField;
235
+ id = (_linkObj$Id = linkObj['@id']) !== null && _linkObj$Id !== void 0 ? _linkObj$Id : linkObj['href'];
236
+ if (!(typeof id === 'string' && id !== url)) {
237
+ _context2.next = 24;
238
+ break;
239
+ }
240
+ return _context2.abrupt("return", id);
241
+ case 24:
242
+ _context2.next = 28;
243
+ break;
244
+ case 26:
245
+ _context2.prev = 26;
246
+ _context2.t0 = _context2["catch"](2);
247
+ case 28:
248
+ return _context2.abrupt("return", undefined);
249
+ case 29:
250
+ case "end":
251
+ return _context2.stop();
252
+ }
253
+ }, _callee2, null, [[2, 26]]);
254
+ }));
255
+ function resolveShortLinkUrl(_x2) {
256
+ return _resolveShortLinkUrl.apply(this, arguments);
257
+ }
258
+ return resolveShortLinkUrl;
259
+ }(),
176
260
  getStartingToolbarItems: (0, _toolbar.getStartingToolbarItems)(options, api),
177
261
  getEndingToolbarItems: (0, _toolbar.getEndingToolbarItems)(options, api)
178
262
  },
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.updateCardViaDatasource = exports.updateCard = exports.setSelectedCardAppearance = exports.replaceQueuedUrlWithCard = exports.queueCardsFromChangedTr = exports.queueCardFromChangedTr = exports.insertDatasource = exports.handleFallbackWithAnalytics = exports.getLinkNodeType = exports.getAttrsForAppearance = exports.convertHyperlinkToSmartCard = exports.changeSelectedCardToText = exports.changeSelectedCardToLinkFallback = exports.changeSelectedCardToLink = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
11
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
11
12
  var _adfSchema = require("@atlaskit/adf-schema");
12
13
  var _analytics = require("@atlaskit/editor-common/analytics");
@@ -14,6 +15,7 @@ var _card = require("@atlaskit/editor-common/card");
14
15
  var _link = require("@atlaskit/editor-common/link");
15
16
  var _utils = require("@atlaskit/editor-common/utils");
16
17
  var _state = require("@atlaskit/editor-prosemirror/state");
18
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
17
19
  var _prosemirrorHistory = require("@atlaskit/prosemirror-history");
18
20
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
19
21
  var _actions = require("./actions");
@@ -78,13 +80,41 @@ var replaceQueuedUrlWithCard = exports.replaceQueuedUrlWithCard = function repla
78
80
 
79
81
  // If an embed card transformer is provided and the resolved card is an embedCard,
80
82
  // attempt to transform it into an alternative node representation first.
81
- if (cardData.type === 'embedCard' && embedCardNodeTransformer) {
82
- var _embedCardNodeTransfo;
83
- cardAdf = (_embedCardNodeTransfo = embedCardNodeTransformer(schema, cardData.attrs)) !== null && _embedCardNodeTransfo !== void 0 ? _embedCardNodeTransfo : null;
83
+ if (cardData.type === 'embedCard' && embedCardNodeTransformer && (0, _platformFeatureFlags.fg)('platform-native-embeds-short-link-expansion')) {
84
+ var transformResult = embedCardNodeTransformer(schema, cardData.attrs);
85
+ // The transformer may return a Promise for async transformations (e.g. short-link expansion).
86
+ // When async, we snapshot the current requests and positions now (before any dispatch),
87
+ // then insert the resolved node and clean up the queue in one transaction once the
88
+ // Promise settles. This avoids the stale-editorState problem: rather than re-running
89
+ // replaceQueuedUrlWithCard with an outdated state snapshot, we capture what we need
90
+ // immediately and apply a targeted insert when ready.
91
+ if (transformResult instanceof Promise) {
92
+ // Snapshot requests now, while the queue still contains this URL.
93
+ var pendingRequests = (0, _toConsumableArray2.default)(requests);
94
+ transformResult.then(function (resolvedNode) {
95
+ var _processRawValue;
96
+ if (!dispatch) {
97
+ return;
98
+ }
99
+ // Build a fresh transaction (editorState is the snapshot at call-time; positions
100
+ // are mapped through it). For the async case we fall back to cardData if the
101
+ // transform returned nothing, mirroring what the sync path would do.
102
+ var asyncCardAdf = resolvedNode ? resolvedNode : (_processRawValue = (0, _utils.processRawValue)(schema, cardData)) !== null && _processRawValue !== void 0 ? _processRawValue : null;
103
+ var asyncTr = editorState.tr;
104
+ if (asyncCardAdf) {
105
+ pendingRequests.forEach(function (request) {
106
+ return replaceLinksToCards(asyncTr, asyncCardAdf, schema, request);
107
+ });
108
+ }
109
+ dispatch((0, _actions.resolveCard)(url)((0, _prosemirrorHistory.closeHistory)(asyncTr)));
110
+ });
111
+ return true;
112
+ }
113
+ cardAdf = transformResult !== null && transformResult !== void 0 ? transformResult : null;
84
114
  }
85
115
  if (!cardAdf) {
86
- var _processRawValue;
87
- cardAdf = (_processRawValue = (0, _utils.processRawValue)(schema, cardData)) !== null && _processRawValue !== void 0 ? _processRawValue : null;
116
+ var _processRawValue2;
117
+ cardAdf = (_processRawValue2 = (0, _utils.processRawValue)(schema, cardData)) !== null && _processRawValue2 !== void 0 ? _processRawValue2 : null;
88
118
  }
89
119
  var tr = editorState.tr;
90
120
  if (cardAdf) {
@@ -12,7 +12,6 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
12
12
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
13
13
  var _react = _interopRequireDefault(require("react"));
14
14
  var _linkProvider = require("@atlaskit/link-provider");
15
- var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
16
15
  var _EditorAnalyticsContext = require("../EditorAnalyticsContext");
17
16
  var _DatasourceEvents = require("./DatasourceEvents");
18
17
  var _LinkEvents = require("./LinkEvents");
@@ -28,7 +27,7 @@ var EditorLinkingPlatformAnalytics = exports.EditorLinkingPlatformAnalytics = /*
28
27
  return (0, _createClass2.default)(EditorLinkingPlatformAnalytics, [{
29
28
  key: "render",
30
29
  value: function render() {
31
- if ((0, _expValEquals.expValEquals)('platform_editor_hydratable_ui', 'isEnabled', true) && !this.props.editorView) {
30
+ if (!this.props.editorView) {
32
31
  return null;
33
32
  }
34
33
  return /*#__PURE__*/_react.default.createElement(_linkProvider.EditorSmartCardProvider, null, /*#__PURE__*/_react.default.createElement(_linkProvider.EditorSmartCardProviderValueGuard, null, /*#__PURE__*/_react.default.createElement(_EditorAnalyticsContext.EditorAnalyticsContext, {
@@ -6,13 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.EditorSmartCardEvents = void 0;
7
7
  var _react = require("react");
8
8
  var _smartCard = require("@atlaskit/smart-card");
9
- var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
10
9
  var _actions = require("../pm-plugins/actions");
11
10
  var EditorSmartCardEvents = exports.EditorSmartCardEvents = function EditorSmartCardEvents(_ref) {
12
11
  var editorView = _ref.editorView;
13
12
  var events = (0, _smartCard.useSmartLinkEvents)();
14
13
  (0, _react.useEffect)(function () {
15
- if (!events || (0, _expValEquals.expValEquals)('platform_editor_hydratable_ui', 'isEnabled', true) && !editorView) {
14
+ if (!events || !editorView) {
16
15
  return;
17
16
  }
18
17
  editorView.dispatch((0, _actions.registerSmartCardEvents)(events)(editorView.state.tr));
@@ -151,6 +151,51 @@ export const cardPlugin = ({
151
151
  registerEmbedCardTransformer: transformers => {
152
152
  instanceEmbedCardTransformers = transformers;
153
153
  },
154
+ resolveShortLinkUrl: async url => {
155
+ if (!options.provider) {
156
+ return undefined;
157
+ }
158
+ try {
159
+ const provider = await options.provider;
160
+ // EditorCardProvider holds a CardClient instance internally. We access it
161
+ // directly to call fetchData, which gives us the raw ORS JSON-LD response
162
+ // including the canonical url field — something provider.resolve() does not
163
+ // surface. This is intentionally a structural cast rather than a typed
164
+ // dependency on EditorCardProvider's private API.
165
+ const clientHolder = provider;
166
+ const client = clientHolder.cardClient;
167
+ if (!client) {
168
+ return undefined;
169
+ }
170
+ const response = await client.fetchData(url);
171
+ // ORS returns a JsonLd.Response whose data union includes BaseData,
172
+ // BaseCollectionData, and BaseCollectionPage. We only care about the
173
+ // `url` field which is present on BaseData (Primitives.Object). Cast
174
+ // to a minimal shape rather than accessing through the full union type.
175
+ const data = response === null || response === void 0 ? void 0 : response.data;
176
+ if (!data) {
177
+ return undefined;
178
+ }
179
+ const urlField = data.url;
180
+ // Property<string | Link> can be a string, a Link object, or an array.
181
+ // Short-link responses always return a plain string URL.
182
+ if (typeof urlField === 'string' && urlField !== url) {
183
+ return urlField;
184
+ }
185
+ // Fallback: Link object shape with href or @id
186
+ if (urlField && typeof urlField === 'object' && !Array.isArray(urlField)) {
187
+ var _linkObj$Id;
188
+ const linkObj = urlField;
189
+ const id = (_linkObj$Id = linkObj['@id']) !== null && _linkObj$Id !== void 0 ? _linkObj$Id : linkObj['href'];
190
+ if (typeof id === 'string' && id !== url) {
191
+ return id;
192
+ }
193
+ }
194
+ } catch {
195
+ // Swallow errors — callers handle undefined
196
+ }
197
+ return undefined;
198
+ },
154
199
  getStartingToolbarItems: getStartingToolbarItems(options, api),
155
200
  getEndingToolbarItems: getEndingToolbarItems(options, api)
156
201
  },
@@ -5,6 +5,7 @@ import { addLinkMetadata } from '@atlaskit/editor-common/card';
5
5
  import { getActiveLinkMark } from '@atlaskit/editor-common/link';
6
6
  import { getAnnotationMarksForPos, getLinkCreationAnalyticsEvent, isFromCurrentDomain, nodesBetweenChanged, processRawValue } from '@atlaskit/editor-common/utils';
7
7
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
8
+ import { fg } from '@atlaskit/platform-feature-flags';
8
9
  import { closeHistory } from '@atlaskit/prosemirror-history';
9
10
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
10
11
  import { hideDatasourceModal, queueCards, removeDatasourceStash, resolveCard, setDatasourceStash } from './actions';
@@ -69,13 +70,39 @@ export const replaceQueuedUrlWithCard = (url, cardData, analyticsAction, editorA
69
70
 
70
71
  // If an embed card transformer is provided and the resolved card is an embedCard,
71
72
  // attempt to transform it into an alternative node representation first.
72
- if (cardData.type === 'embedCard' && embedCardNodeTransformer) {
73
- var _embedCardNodeTransfo;
74
- cardAdf = (_embedCardNodeTransfo = embedCardNodeTransformer(schema, cardData.attrs)) !== null && _embedCardNodeTransfo !== void 0 ? _embedCardNodeTransfo : null;
73
+ if (cardData.type === 'embedCard' && embedCardNodeTransformer && fg('platform-native-embeds-short-link-expansion')) {
74
+ const transformResult = embedCardNodeTransformer(schema, cardData.attrs);
75
+ // The transformer may return a Promise for async transformations (e.g. short-link expansion).
76
+ // When async, we snapshot the current requests and positions now (before any dispatch),
77
+ // then insert the resolved node and clean up the queue in one transaction once the
78
+ // Promise settles. This avoids the stale-editorState problem: rather than re-running
79
+ // replaceQueuedUrlWithCard with an outdated state snapshot, we capture what we need
80
+ // immediately and apply a targeted insert when ready.
81
+ if (transformResult instanceof Promise) {
82
+ // Snapshot requests now, while the queue still contains this URL.
83
+ const pendingRequests = [...requests];
84
+ transformResult.then(resolvedNode => {
85
+ var _processRawValue;
86
+ if (!dispatch) {
87
+ return;
88
+ }
89
+ // Build a fresh transaction (editorState is the snapshot at call-time; positions
90
+ // are mapped through it). For the async case we fall back to cardData if the
91
+ // transform returned nothing, mirroring what the sync path would do.
92
+ const asyncCardAdf = resolvedNode ? resolvedNode : (_processRawValue = processRawValue(schema, cardData)) !== null && _processRawValue !== void 0 ? _processRawValue : null;
93
+ const asyncTr = editorState.tr;
94
+ if (asyncCardAdf) {
95
+ pendingRequests.forEach(request => replaceLinksToCards(asyncTr, asyncCardAdf, schema, request));
96
+ }
97
+ dispatch(resolveCard(url)(closeHistory(asyncTr)));
98
+ });
99
+ return true;
100
+ }
101
+ cardAdf = transformResult !== null && transformResult !== void 0 ? transformResult : null;
75
102
  }
76
103
  if (!cardAdf) {
77
- var _processRawValue;
78
- cardAdf = (_processRawValue = processRawValue(schema, cardData)) !== null && _processRawValue !== void 0 ? _processRawValue : null;
104
+ var _processRawValue2;
105
+ cardAdf = (_processRawValue2 = processRawValue(schema, cardData)) !== null && _processRawValue2 !== void 0 ? _processRawValue2 : null;
79
106
  }
80
107
  const tr = editorState.tr;
81
108
  if (cardAdf) {
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
2
  import { EditorSmartCardProvider, EditorSmartCardProviderValueGuard } from '@atlaskit/link-provider';
3
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
3
  import { EditorAnalyticsContext } from '../EditorAnalyticsContext';
5
4
  import { DatasourceEventsBinding } from './DatasourceEvents';
6
5
  import { LinkEventsBinding } from './LinkEvents';
@@ -8,7 +7,7 @@ import { LinkEventsBinding } from './LinkEvents';
8
7
  // eslint-disable-next-line @repo/internal/react/no-class-components
9
8
  export class EditorLinkingPlatformAnalytics extends React.PureComponent {
10
9
  render() {
11
- if (expValEquals('platform_editor_hydratable_ui', 'isEnabled', true) && !this.props.editorView) {
10
+ if (!this.props.editorView) {
12
11
  return null;
13
12
  }
14
13
  return /*#__PURE__*/React.createElement(EditorSmartCardProvider, null, /*#__PURE__*/React.createElement(EditorSmartCardProviderValueGuard, null, /*#__PURE__*/React.createElement(EditorAnalyticsContext, {
@@ -1,13 +1,12 @@
1
1
  import { useEffect } from 'react';
2
2
  import { useSmartLinkEvents } from '@atlaskit/smart-card';
3
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
3
  import { registerSmartCardEvents } from '../pm-plugins/actions';
5
4
  export const EditorSmartCardEvents = ({
6
5
  editorView
7
6
  }) => {
8
7
  const events = useSmartLinkEvents();
9
8
  useEffect(() => {
10
- if (!events || expValEquals('platform_editor_hydratable_ui', 'isEnabled', true) && !editorView) {
9
+ if (!events || !editorView) {
11
10
  return;
12
11
  }
13
12
  editorView.dispatch(registerSmartCardEvents(events)(editorView.state.tr));
@@ -1,3 +1,4 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
1
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
@@ -167,6 +168,89 @@ export var cardPlugin = function cardPlugin(_ref) {
167
168
  registerEmbedCardTransformer: function registerEmbedCardTransformer(transformers) {
168
169
  instanceEmbedCardTransformers = transformers;
169
170
  },
171
+ resolveShortLinkUrl: function () {
172
+ var _resolveShortLinkUrl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(url) {
173
+ var provider, clientHolder, client, response, data, urlField, _linkObj$Id, linkObj, id;
174
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
175
+ while (1) switch (_context2.prev = _context2.next) {
176
+ case 0:
177
+ if (options.provider) {
178
+ _context2.next = 2;
179
+ break;
180
+ }
181
+ return _context2.abrupt("return", undefined);
182
+ case 2:
183
+ _context2.prev = 2;
184
+ _context2.next = 5;
185
+ return options.provider;
186
+ case 5:
187
+ provider = _context2.sent;
188
+ // EditorCardProvider holds a CardClient instance internally. We access it
189
+ // directly to call fetchData, which gives us the raw ORS JSON-LD response
190
+ // including the canonical url field — something provider.resolve() does not
191
+ // surface. This is intentionally a structural cast rather than a typed
192
+ // dependency on EditorCardProvider's private API.
193
+ clientHolder = provider;
194
+ client = clientHolder.cardClient;
195
+ if (client) {
196
+ _context2.next = 10;
197
+ break;
198
+ }
199
+ return _context2.abrupt("return", undefined);
200
+ case 10:
201
+ _context2.next = 12;
202
+ return client.fetchData(url);
203
+ case 12:
204
+ response = _context2.sent;
205
+ // ORS returns a JsonLd.Response whose data union includes BaseData,
206
+ // BaseCollectionData, and BaseCollectionPage. We only care about the
207
+ // `url` field which is present on BaseData (Primitives.Object). Cast
208
+ // to a minimal shape rather than accessing through the full union type.
209
+ data = response === null || response === void 0 ? void 0 : response.data;
210
+ if (data) {
211
+ _context2.next = 16;
212
+ break;
213
+ }
214
+ return _context2.abrupt("return", undefined);
215
+ case 16:
216
+ urlField = data.url; // Property<string | Link> can be a string, a Link object, or an array.
217
+ // Short-link responses always return a plain string URL.
218
+ if (!(typeof urlField === 'string' && urlField !== url)) {
219
+ _context2.next = 19;
220
+ break;
221
+ }
222
+ return _context2.abrupt("return", urlField);
223
+ case 19:
224
+ if (!(urlField && _typeof(urlField) === 'object' && !Array.isArray(urlField))) {
225
+ _context2.next = 24;
226
+ break;
227
+ }
228
+ linkObj = urlField;
229
+ id = (_linkObj$Id = linkObj['@id']) !== null && _linkObj$Id !== void 0 ? _linkObj$Id : linkObj['href'];
230
+ if (!(typeof id === 'string' && id !== url)) {
231
+ _context2.next = 24;
232
+ break;
233
+ }
234
+ return _context2.abrupt("return", id);
235
+ case 24:
236
+ _context2.next = 28;
237
+ break;
238
+ case 26:
239
+ _context2.prev = 26;
240
+ _context2.t0 = _context2["catch"](2);
241
+ case 28:
242
+ return _context2.abrupt("return", undefined);
243
+ case 29:
244
+ case "end":
245
+ return _context2.stop();
246
+ }
247
+ }, _callee2, null, [[2, 26]]);
248
+ }));
249
+ function resolveShortLinkUrl(_x2) {
250
+ return _resolveShortLinkUrl.apply(this, arguments);
251
+ }
252
+ return resolveShortLinkUrl;
253
+ }(),
170
254
  getStartingToolbarItems: getStartingToolbarItems(options, api),
171
255
  getEndingToolbarItems: getEndingToolbarItems(options, api)
172
256
  },
@@ -1,5 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
4
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
5
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
6
  import isEqual from 'lodash/isEqual';
@@ -9,6 +10,7 @@ import { addLinkMetadata } from '@atlaskit/editor-common/card';
9
10
  import { getActiveLinkMark } from '@atlaskit/editor-common/link';
10
11
  import { getAnnotationMarksForPos, getLinkCreationAnalyticsEvent, isFromCurrentDomain, nodesBetweenChanged, processRawValue } from '@atlaskit/editor-common/utils';
11
12
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
13
+ import { fg } from '@atlaskit/platform-feature-flags';
12
14
  import { closeHistory } from '@atlaskit/prosemirror-history';
13
15
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
14
16
  import { hideDatasourceModal, queueCards, removeDatasourceStash, resolveCard, setDatasourceStash } from './actions';
@@ -72,13 +74,41 @@ export var replaceQueuedUrlWithCard = function replaceQueuedUrlWithCard(url, car
72
74
 
73
75
  // If an embed card transformer is provided and the resolved card is an embedCard,
74
76
  // attempt to transform it into an alternative node representation first.
75
- if (cardData.type === 'embedCard' && embedCardNodeTransformer) {
76
- var _embedCardNodeTransfo;
77
- cardAdf = (_embedCardNodeTransfo = embedCardNodeTransformer(schema, cardData.attrs)) !== null && _embedCardNodeTransfo !== void 0 ? _embedCardNodeTransfo : null;
77
+ if (cardData.type === 'embedCard' && embedCardNodeTransformer && fg('platform-native-embeds-short-link-expansion')) {
78
+ var transformResult = embedCardNodeTransformer(schema, cardData.attrs);
79
+ // The transformer may return a Promise for async transformations (e.g. short-link expansion).
80
+ // When async, we snapshot the current requests and positions now (before any dispatch),
81
+ // then insert the resolved node and clean up the queue in one transaction once the
82
+ // Promise settles. This avoids the stale-editorState problem: rather than re-running
83
+ // replaceQueuedUrlWithCard with an outdated state snapshot, we capture what we need
84
+ // immediately and apply a targeted insert when ready.
85
+ if (transformResult instanceof Promise) {
86
+ // Snapshot requests now, while the queue still contains this URL.
87
+ var pendingRequests = _toConsumableArray(requests);
88
+ transformResult.then(function (resolvedNode) {
89
+ var _processRawValue;
90
+ if (!dispatch) {
91
+ return;
92
+ }
93
+ // Build a fresh transaction (editorState is the snapshot at call-time; positions
94
+ // are mapped through it). For the async case we fall back to cardData if the
95
+ // transform returned nothing, mirroring what the sync path would do.
96
+ var asyncCardAdf = resolvedNode ? resolvedNode : (_processRawValue = processRawValue(schema, cardData)) !== null && _processRawValue !== void 0 ? _processRawValue : null;
97
+ var asyncTr = editorState.tr;
98
+ if (asyncCardAdf) {
99
+ pendingRequests.forEach(function (request) {
100
+ return replaceLinksToCards(asyncTr, asyncCardAdf, schema, request);
101
+ });
102
+ }
103
+ dispatch(resolveCard(url)(closeHistory(asyncTr)));
104
+ });
105
+ return true;
106
+ }
107
+ cardAdf = transformResult !== null && transformResult !== void 0 ? transformResult : null;
78
108
  }
79
109
  if (!cardAdf) {
80
- var _processRawValue;
81
- cardAdf = (_processRawValue = processRawValue(schema, cardData)) !== null && _processRawValue !== void 0 ? _processRawValue : null;
110
+ var _processRawValue2;
111
+ cardAdf = (_processRawValue2 = processRawValue(schema, cardData)) !== null && _processRawValue2 !== void 0 ? _processRawValue2 : null;
82
112
  }
83
113
  var tr = editorState.tr;
84
114
  if (cardAdf) {
@@ -7,7 +7,6 @@ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstruct
7
7
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
8
8
  import React from 'react';
9
9
  import { EditorSmartCardProvider, EditorSmartCardProviderValueGuard } from '@atlaskit/link-provider';
10
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
11
10
  import { EditorAnalyticsContext } from '../EditorAnalyticsContext';
12
11
  import { DatasourceEventsBinding } from './DatasourceEvents';
13
12
  import { LinkEventsBinding } from './LinkEvents';
@@ -22,7 +21,7 @@ export var EditorLinkingPlatformAnalytics = /*#__PURE__*/function (_React$PureCo
22
21
  return _createClass(EditorLinkingPlatformAnalytics, [{
23
22
  key: "render",
24
23
  value: function render() {
25
- if (expValEquals('platform_editor_hydratable_ui', 'isEnabled', true) && !this.props.editorView) {
24
+ if (!this.props.editorView) {
26
25
  return null;
27
26
  }
28
27
  return /*#__PURE__*/React.createElement(EditorSmartCardProvider, null, /*#__PURE__*/React.createElement(EditorSmartCardProviderValueGuard, null, /*#__PURE__*/React.createElement(EditorAnalyticsContext, {
@@ -1,12 +1,11 @@
1
1
  import { useEffect } from 'react';
2
2
  import { useSmartLinkEvents } from '@atlaskit/smart-card';
3
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
3
  import { registerSmartCardEvents } from '../pm-plugins/actions';
5
4
  export var EditorSmartCardEvents = function EditorSmartCardEvents(_ref) {
6
5
  var editorView = _ref.editorView;
7
6
  var events = useSmartLinkEvents();
8
7
  useEffect(function () {
9
- if (!events || expValEquals('platform_editor_hydratable_ui', 'isEnabled', true) && !editorView) {
8
+ if (!events || !editorView) {
10
9
  return;
11
10
  }
12
11
  editorView.dispatch(registerSmartCardEvents(events)(editorView.state.tr));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-card",
3
- "version": "16.1.0",
3
+ "version": "16.3.0",
4
4
  "description": "Card plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -41,18 +41,18 @@
41
41
  "@atlaskit/editor-plugin-editor-viewmode": "^12.0.0",
42
42
  "@atlaskit/editor-plugin-feature-flags": "^9.0.0",
43
43
  "@atlaskit/editor-plugin-floating-toolbar": "^12.0.0",
44
- "@atlaskit/editor-plugin-grid": "^10.0.0",
44
+ "@atlaskit/editor-plugin-grid": "^10.1.0",
45
45
  "@atlaskit/editor-plugin-toolbar": "^7.0.0",
46
46
  "@atlaskit/editor-plugin-width": "^11.0.0",
47
47
  "@atlaskit/editor-prosemirror": "^7.3.0",
48
48
  "@atlaskit/editor-shared-styles": "^3.10.0",
49
49
  "@atlaskit/editor-smart-link-draggable": "^0.5.0",
50
50
  "@atlaskit/frontend-utilities": "^3.2.0",
51
- "@atlaskit/icon": "^34.2.0",
51
+ "@atlaskit/icon": "^34.3.0",
52
52
  "@atlaskit/link": "^3.4.0",
53
53
  "@atlaskit/link-analytics": "^11.0.0",
54
54
  "@atlaskit/link-client-extension": "^6.0.0",
55
- "@atlaskit/link-datasource": "^5.1.0",
55
+ "@atlaskit/link-datasource": "^5.2.0",
56
56
  "@atlaskit/link-extractors": "^2.4.0",
57
57
  "@atlaskit/linking-common": "^9.11.0",
58
58
  "@atlaskit/linking-types": "^14.2.0",
@@ -62,7 +62,7 @@
62
62
  "@atlaskit/primitives": "^19.0.0",
63
63
  "@atlaskit/prosemirror-history": "^0.2.0",
64
64
  "@atlaskit/smart-card": "^44.3.0",
65
- "@atlaskit/tmp-editor-statsig": "^64.0.0",
65
+ "@atlaskit/tmp-editor-statsig": "^66.0.0",
66
66
  "@atlaskit/tokens": "^13.0.0",
67
67
  "@babel/runtime": "^7.0.0",
68
68
  "@emotion/react": "^11.7.1",
@@ -72,7 +72,7 @@
72
72
  "uuid": "^3.1.0"
73
73
  },
74
74
  "peerDependencies": {
75
- "@atlaskit/editor-common": "^114.6.0",
75
+ "@atlaskit/editor-common": "^114.7.0",
76
76
  "@atlaskit/link-provider": "^4.3.0",
77
77
  "react": "^18.2.0",
78
78
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
@@ -111,6 +111,9 @@
111
111
  }
112
112
  },
113
113
  "platform-feature-flags": {
114
+ "platform-native-embeds-short-link-expansion": {
115
+ "type": "boolean"
116
+ },
114
117
  "cc_drag_and_drop_smart_link_from_content_to_tree": {
115
118
  "type": "boolean"
116
119
  },