@atlaskit/editor-plugin-card 2.9.1 → 2.9.3

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 (38) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/nodeviews/blockCard.js +45 -2
  3. package/dist/cjs/nodeviews/embedCard.js +29 -2
  4. package/dist/cjs/nodeviews/lazy-block-card.js +32 -0
  5. package/dist/cjs/nodeviews/lazy-embed-card.js +32 -0
  6. package/dist/cjs/plugin.js +4 -2
  7. package/dist/cjs/pm-plugins/main.js +29 -60
  8. package/dist/cjs/toDOM-fixes/blockCard.js +53 -0
  9. package/dist/cjs/toDOM-fixes/embedCard.js +118 -0
  10. package/dist/es2019/nodeviews/blockCard.js +46 -2
  11. package/dist/es2019/nodeviews/embedCard.js +29 -1
  12. package/dist/es2019/nodeviews/lazy-block-card.js +21 -0
  13. package/dist/es2019/nodeviews/lazy-embed-card.js +21 -0
  14. package/dist/es2019/plugin.js +5 -3
  15. package/dist/es2019/pm-plugins/main.js +23 -58
  16. package/dist/es2019/toDOM-fixes/blockCard.js +47 -0
  17. package/dist/es2019/toDOM-fixes/embedCard.js +111 -0
  18. package/dist/esm/nodeviews/blockCard.js +45 -2
  19. package/dist/esm/nodeviews/embedCard.js +28 -1
  20. package/dist/esm/nodeviews/lazy-block-card.js +20 -0
  21. package/dist/esm/nodeviews/lazy-embed-card.js +20 -0
  22. package/dist/esm/plugin.js +5 -3
  23. package/dist/esm/pm-plugins/main.js +23 -54
  24. package/dist/esm/toDOM-fixes/blockCard.js +46 -0
  25. package/dist/esm/toDOM-fixes/embedCard.js +112 -0
  26. package/dist/types/nodeviews/blockCard.d.ts +15 -2
  27. package/dist/types/nodeviews/embedCard.d.ts +14 -0
  28. package/dist/types/nodeviews/lazy-block-card.d.ts +2 -0
  29. package/dist/types/nodeviews/lazy-embed-card.d.ts +2 -0
  30. package/dist/types/toDOM-fixes/blockCard.d.ts +1 -0
  31. package/dist/types/toDOM-fixes/embedCard.d.ts +1 -0
  32. package/dist/types-ts4.5/nodeviews/blockCard.d.ts +15 -2
  33. package/dist/types-ts4.5/nodeviews/embedCard.d.ts +14 -0
  34. package/dist/types-ts4.5/nodeviews/lazy-block-card.d.ts +2 -0
  35. package/dist/types-ts4.5/nodeviews/lazy-embed-card.d.ts +2 -0
  36. package/dist/types-ts4.5/toDOM-fixes/blockCard.d.ts +1 -0
  37. package/dist/types-ts4.5/toDOM-fixes/embedCard.d.ts +1 -0
  38. package/package.json +13 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atlaskit/editor-plugin-card
2
2
 
3
+ ## 2.9.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#125862](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/125862)
8
+ [`6c72c192b5df6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/6c72c192b5df6) -
9
+ [ux] Improve embed card fallback for lazy node view such that it matches the embed card loading
10
+ state.
11
+ - Updated dependencies
12
+
13
+ ## 2.9.2
14
+
15
+ ### Patch Changes
16
+
17
+ - [#125851](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/125851)
18
+ [`4ffe0a8ea7929`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4ffe0a8ea7929) -
19
+ Refactor node views.
20
+ - Updated dependencies
21
+
3
22
  ## 2.9.1
4
23
 
5
24
  ### Patch Changes
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.BlockCardComponent = exports.BlockCard = void 0;
7
+ exports.blockCardNodeView = exports.BlockCardComponent = exports.BlockCard = void 0;
8
8
  var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
9
9
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
10
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -21,6 +21,7 @@ var _ui = require("@atlaskit/editor-common/ui");
21
21
  var _utils = require("@atlaskit/editor-common/utils");
22
22
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
23
23
  var _smartCard = require("@atlaskit/smart-card");
24
+ var _datasource = require("../nodeviews/datasource");
24
25
  var _actions = require("../pm-plugins/actions");
25
26
  var _utils2 = require("../utils");
26
27
  var _genericCard = require("./genericCard");
@@ -211,4 +212,46 @@ var BlockCard = exports.BlockCard = /*#__PURE__*/function (_ReactNodeView) {
211
212
  }
212
213
  }]);
213
214
  return BlockCard;
214
- }(_reactNodeView.default);
215
+ }(_reactNodeView.default);
216
+ var blockCardNodeView = exports.blockCardNodeView = function blockCardNodeView(_ref3) {
217
+ var pmPluginFactoryParams = _ref3.pmPluginFactoryParams,
218
+ platform = _ref3.platform,
219
+ actionOptions = _ref3.actionOptions,
220
+ showServerActions = _ref3.showServerActions,
221
+ pluginInjectionApi = _ref3.pluginInjectionApi,
222
+ onClickCallback = _ref3.onClickCallback,
223
+ allowDatasource = _ref3.allowDatasource,
224
+ inlineCardViewProducer = _ref3.inlineCardViewProducer;
225
+ return function (node, view, getPos, decorations) {
226
+ var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
227
+ eventDispatcher = pmPluginFactoryParams.eventDispatcher;
228
+ var reactComponentProps = {
229
+ platform: platform,
230
+ actionOptions: actionOptions,
231
+ showServerActions: showServerActions,
232
+ pluginInjectionApi: pluginInjectionApi,
233
+ onClickCallback: onClickCallback
234
+ };
235
+ var isDatasource = (0, _utils2.isDatasourceNode)(node);
236
+ if (isDatasource) {
237
+ var _node$attrs2;
238
+ if (allowDatasource && platform !== 'mobile' && (0, _utils.canRenderDatasource)(node === null || node === void 0 || (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 || (_node$attrs2 = _node$attrs2.datasource) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.id)) {
239
+ var datasourcePosition = typeof getPos === 'function' && getPos();
240
+ var datasourceResolvedPosition = datasourcePosition && view.state.doc.resolve(datasourcePosition);
241
+ var isNodeNested = !!(datasourceResolvedPosition && datasourceResolvedPosition.depth > 0);
242
+ return new _datasource.Datasource({
243
+ node: node,
244
+ view: view,
245
+ getPos: getPos,
246
+ portalProviderAPI: portalProviderAPI,
247
+ eventDispatcher: eventDispatcher,
248
+ pluginInjectionApi: pluginInjectionApi,
249
+ isNodeNested: isNodeNested
250
+ }).init();
251
+ } else {
252
+ return inlineCardViewProducer(node, view, getPos, decorations);
253
+ }
254
+ }
255
+ return new BlockCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
256
+ };
257
+ };
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.EmbedCardComponent = exports.EmbedCard = void 0;
7
+ exports.embedCardNodeView = exports.EmbedCardComponent = exports.EmbedCard = void 0;
8
8
  var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
9
9
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
10
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -423,4 +423,31 @@ var EmbedCard = exports.EmbedCard = /*#__PURE__*/function (_ReactNodeView) {
423
423
  }
424
424
  }]);
425
425
  return EmbedCard;
426
- }(_reactNodeView.default);
426
+ }(_reactNodeView.default);
427
+ var embedCardNodeView = exports.embedCardNodeView = function embedCardNodeView(_ref4) {
428
+ var allowResizing = _ref4.allowResizing,
429
+ platform = _ref4.platform,
430
+ fullWidthMode = _ref4.fullWidthMode,
431
+ pmPluginFactoryParams = _ref4.pmPluginFactoryParams,
432
+ pluginInjectionApi = _ref4.pluginInjectionApi,
433
+ actionOptions = _ref4.actionOptions,
434
+ showServerActions = _ref4.showServerActions,
435
+ onClickCallback = _ref4.onClickCallback;
436
+ return function (node, view, getPos) {
437
+ var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
438
+ eventDispatcher = pmPluginFactoryParams.eventDispatcher,
439
+ dispatchAnalyticsEvent = pmPluginFactoryParams.dispatchAnalyticsEvent;
440
+ var reactComponentProps = {
441
+ eventDispatcher: eventDispatcher,
442
+ allowResizing: allowResizing,
443
+ platform: platform,
444
+ fullWidthMode: fullWidthMode,
445
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
446
+ pluginInjectionApi: pluginInjectionApi,
447
+ actionOptions: actionOptions,
448
+ showServerActions: showServerActions,
449
+ onClickCallback: onClickCallback
450
+ };
451
+ return new EmbedCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
452
+ };
453
+ };
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.lazyBlockCardView = void 0;
8
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
+ var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
10
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
+ var _blockCard = require("./blockCard");
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != (0, _typeof2.default)(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ var lazyBlockCardView = exports.lazyBlockCardView = function lazyBlockCardView(props) {
15
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_lazy-node-views')) {
16
+ return (0, _blockCard.blockCardNodeView)(props);
17
+ }
18
+ return (0, _lazyNodeView.withLazyLoading)({
19
+ nodeName: 'blockCard',
20
+ getNodeViewOptions: function getNodeViewOptions() {},
21
+ loader: function loader() {
22
+ var result = Promise.resolve().then(function () {
23
+ return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_editor-plugin-tasks-and-decisions_task-item-nodeview" */
24
+ './blockCard'));
25
+ }).then(function (_ref) {
26
+ var blockCardNodeView = _ref.blockCardNodeView;
27
+ return blockCardNodeView(props);
28
+ });
29
+ return result;
30
+ }
31
+ });
32
+ };
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.lazyEmbedCardView = void 0;
8
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
+ var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
10
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
+ var _embedCard = require("./embedCard");
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != (0, _typeof2.default)(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ var lazyEmbedCardView = exports.lazyEmbedCardView = function lazyEmbedCardView(props) {
15
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_lazy-node-views')) {
16
+ return (0, _embedCard.embedCardNodeView)(props);
17
+ }
18
+ return (0, _lazyNodeView.withLazyLoading)({
19
+ nodeName: 'embedCard',
20
+ getNodeViewOptions: function getNodeViewOptions() {},
21
+ loader: function loader() {
22
+ var result = Promise.resolve().then(function () {
23
+ return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_editor-plugin-embed-card-item-nodeview" */
24
+ './embedCard'));
25
+ }).then(function (_ref) {
26
+ var embedCardNodeView = _ref.embedCardNodeView;
27
+ return embedCardNodeView(props);
28
+ });
29
+ return result;
30
+ }
31
+ });
32
+ };
@@ -18,6 +18,8 @@ var _doc = require("./pm-plugins/doc");
18
18
  var _keymap = require("./pm-plugins/keymap");
19
19
  var _main = require("./pm-plugins/main");
20
20
  var _pluginKey = require("./pm-plugins/plugin-key");
21
+ var _blockCard = require("./toDOM-fixes/blockCard");
22
+ var _embedCard = require("./toDOM-fixes/embedCard");
21
23
  var _toolbar = require("./toolbar");
22
24
  var _ModalWithState = _interopRequireDefault(require("./ui/DatasourceModal/ModalWithState"));
23
25
  var _EditorLinkingPlatformAnalytics = require("./ui/EditorLinkingPlatformAnalytics");
@@ -45,12 +47,12 @@ var cardPlugin = exports.cardPlugin = function cardPlugin(_ref) {
45
47
  node: _adfSchema.inlineCard
46
48
  }, {
47
49
  name: 'blockCard',
48
- node: _adfSchema.blockCard
50
+ node: (0, _blockCard.blockCardSpecWithFixedToDOM)()
49
51
  }];
50
52
  if (options.allowEmbeds) {
51
53
  nodes.push({
52
54
  name: 'embedCard',
53
- node: _adfSchema.embedCard
55
+ node: (0, _embedCard.embedCardSpecWithFixedToDOM)()
54
56
  });
55
57
  }
56
58
  return nodes;
@@ -18,19 +18,17 @@ var _rafSchd = _interopRequireDefault(require("raf-schd"));
18
18
  var _reactNodeView = require("@atlaskit/editor-common/react-node-view");
19
19
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
20
20
  var _styles = require("@atlaskit/editor-common/styles");
21
- var _utils = require("@atlaskit/editor-common/utils");
22
21
  var _state = require("@atlaskit/editor-prosemirror/state");
23
- var _utils2 = require("@atlaskit/editor-prosemirror/utils");
22
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
24
23
  var _linkingCommon = require("@atlaskit/linking-common");
25
24
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
26
25
  var _eventsFromTr = require("../analytics/events-from-tr");
27
26
  var _localStorage = require("../common/local-storage");
28
- var _blockCard = require("../nodeviews/blockCard");
29
- var _datasource = require("../nodeviews/datasource");
30
- var _embedCard = require("../nodeviews/embedCard");
31
27
  var _inlineCard = require("../nodeviews/inlineCard");
32
- var _utils3 = require("../ui/LayoutButton/utils");
33
- var _utils4 = require("../utils");
28
+ var _lazyBlockCard = require("../nodeviews/lazy-block-card");
29
+ var _lazyEmbedCard = require("../nodeviews/lazy-embed-card");
30
+ var _utils2 = require("../ui/LayoutButton/utils");
31
+ var _utils3 = require("../utils");
34
32
  var _actions = require("./actions");
35
33
  var _pluginKey = require("./plugin-key");
36
34
  var _reducers = _interopRequireDefault(require("./reducers"));
@@ -152,8 +150,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pluginI
152
150
  return newState;
153
151
  }
154
152
  var linkPosition = pluginState.requests[0].pos;
155
- var canBeUpgradedToBlock = allowBlockCards && (0, _utils4.isBlockSupportedAtPosition)(linkPosition, prevEditorState, 'inline');
156
- var canBeUpgradedToEmbed = allowEmbeds && (0, _utils4.isEmbedSupportedAtPosition)(linkPosition, prevEditorState, 'inline');
153
+ var canBeUpgradedToBlock = allowBlockCards && (0, _utils3.isBlockSupportedAtPosition)(linkPosition, prevEditorState, 'inline');
154
+ var canBeUpgradedToEmbed = allowEmbeds && (0, _utils3.isEmbedSupportedAtPosition)(linkPosition, prevEditorState, 'inline');
157
155
  if (canBeUpgradedToBlock || canBeUpgradedToEmbed) {
158
156
  newState.overlayCandidatePosition = linkPosition;
159
157
  }
@@ -187,13 +185,13 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pluginI
187
185
  var isBlockCardSelected = selection instanceof _state.NodeSelection && ((_selection$node = selection.node) === null || _selection$node === void 0 ? void 0 : _selection$node.type) === schema.nodes.blockCard;
188
186
  if (isBlockCardSelected) {
189
187
  var _findDomRefAtPos, _node$attrs;
190
- var datasourceTableRef = (_findDomRefAtPos = (0, _utils2.findDomRefAtPos)(selection.from, domAtPos)) === null || _findDomRefAtPos === void 0 ? void 0 : _findDomRefAtPos.querySelector(".".concat(_styles.DATASOURCE_INNER_CONTAINER_CLASSNAME));
188
+ var datasourceTableRef = (_findDomRefAtPos = (0, _utils.findDomRefAtPos)(selection.from, domAtPos)) === null || _findDomRefAtPos === void 0 ? void 0 : _findDomRefAtPos.querySelector(".".concat(_styles.DATASOURCE_INNER_CONTAINER_CLASSNAME));
191
189
  var node = selection.node;
192
190
  var isDatasource = !!(node !== null && node !== void 0 && (_node$attrs = node.attrs) !== null && _node$attrs !== void 0 && _node$attrs.datasource);
193
191
  var shouldUpdateTableRef = datasourceTableRef && (currentState === null || currentState === void 0 ? void 0 : currentState.datasourceTableRef) !== datasourceTableRef;
194
192
  if (isDatasource && shouldUpdateTableRef) {
195
193
  // since we use the plugin state, which is a shared state, we need to update the datasourceTableRef, layout on each selection
196
- var layout = (0, _utils3.isDatasourceTableLayout)(node.attrs.layout) ? node.attrs.layout : _linkingCommon.DATASOURCE_DEFAULT_LAYOUT;
194
+ var layout = (0, _utils2.isDatasourceTableLayout)(node.attrs.layout) ? node.attrs.layout : _linkingCommon.DATASOURCE_DEFAULT_LAYOUT;
197
195
  var isNested = selection.$anchor.depth > 0;
198
196
 
199
197
  // we want to disable resize button when datasource table is nested by not setting then datasourceTableRef on selection
@@ -255,55 +253,26 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pluginI
255
253
  props: _objectSpread({
256
254
  nodeViews: {
257
255
  inlineCard: inlineCardViewProducer,
258
- blockCard: function blockCard(node, view, getPos, decorations) {
259
- var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
260
- eventDispatcher = pmPluginFactoryParams.eventDispatcher;
261
- var reactComponentProps = {
262
- platform: platform,
263
- actionOptions: actionOptions,
264
- showServerActions: showServerActions,
265
- pluginInjectionApi: pluginInjectionApi,
266
- onClickCallback: options.onClickCallback
267
- };
268
- var isDatasource = (0, _utils4.isDatasourceNode)(node);
269
- if (isDatasource) {
270
- var _node$attrs2;
271
- if (options.allowDatasource && platform !== 'mobile' && (0, _utils.canRenderDatasource)(node === null || node === void 0 || (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 || (_node$attrs2 = _node$attrs2.datasource) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.id)) {
272
- var datasourcePosition = typeof getPos === 'function' && getPos();
273
- var datasourceResolvedPosition = datasourcePosition && view.state.doc.resolve(datasourcePosition);
274
- var isNodeNested = !!(datasourceResolvedPosition && datasourceResolvedPosition.depth > 0);
275
- return new _datasource.Datasource({
276
- node: node,
277
- view: view,
278
- getPos: getPos,
279
- portalProviderAPI: portalProviderAPI,
280
- eventDispatcher: eventDispatcher,
281
- pluginInjectionApi: pluginInjectionApi,
282
- isNodeNested: isNodeNested
283
- }).init();
284
- } else {
285
- return inlineCardViewProducer(node, view, getPos, decorations);
286
- }
287
- }
288
- return new _blockCard.BlockCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
289
- },
290
- embedCard: function embedCard(node, view, getPos) {
291
- var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
292
- eventDispatcher = pmPluginFactoryParams.eventDispatcher,
293
- dispatchAnalyticsEvent = pmPluginFactoryParams.dispatchAnalyticsEvent;
294
- var reactComponentProps = {
295
- eventDispatcher: eventDispatcher,
296
- allowResizing: allowResizing,
297
- platform: platform,
298
- fullWidthMode: fullWidthMode,
299
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
300
- pluginInjectionApi: pluginInjectionApi,
301
- actionOptions: actionOptions,
302
- showServerActions: showServerActions,
303
- onClickCallback: options.onClickCallback
304
- };
305
- return new _embedCard.EmbedCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
306
- }
256
+ blockCard: (0, _lazyBlockCard.lazyBlockCardView)({
257
+ pmPluginFactoryParams: pmPluginFactoryParams,
258
+ platform: platform,
259
+ actionOptions: actionOptions,
260
+ showServerActions: showServerActions,
261
+ pluginInjectionApi: pluginInjectionApi,
262
+ onClickCallback: onClickCallback,
263
+ allowDatasource: options.allowDatasource,
264
+ inlineCardViewProducer: inlineCardViewProducer
265
+ }),
266
+ embedCard: (0, _lazyEmbedCard.lazyEmbedCardView)({
267
+ allowResizing: allowResizing,
268
+ platform: platform,
269
+ fullWidthMode: fullWidthMode,
270
+ pmPluginFactoryParams: pmPluginFactoryParams,
271
+ pluginInjectionApi: pluginInjectionApi,
272
+ actionOptions: actionOptions,
273
+ showServerActions: showServerActions,
274
+ onClickCallback: options.onClickCallback
275
+ })
307
276
  }
308
277
  }, enableInlineUpgradeFeatures && {
309
278
  handleKeyDown: function handleKeyDown(view) {
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.blockCardSpecWithFixedToDOM = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _adfSchema = require("@atlaskit/adf-schema");
10
+ var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
11
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
+ 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; }
13
+ 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) { (0, _defineProperty2.default)(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; }
14
+ // @nodeSpecException:toDOM patch
15
+ var blockCardSpecWithFixedToDOM = exports.blockCardSpecWithFixedToDOM = function blockCardSpecWithFixedToDOM() {
16
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_lazy-node-views')) {
17
+ return _adfSchema.blockCard;
18
+ }
19
+ return _objectSpread(_objectSpread({}, _adfSchema.blockCard), {}, {
20
+ toDOM: function toDOM(node) {
21
+ var _node$attrs;
22
+ var _ref = node.attrs,
23
+ url = _ref.url;
24
+ var _ref2 = node.attrs,
25
+ data = _ref2.data;
26
+ var _ref3 = node.attrs,
27
+ layout = _ref3.layout,
28
+ width = _ref3.width,
29
+ datasource = _ref3.datasource;
30
+ var attrs = {
31
+ 'data-block-card': '',
32
+ 'data-card-url': url || '',
33
+ 'data-card-data': data ? JSON.stringify(data) : '',
34
+ 'data-datasource': datasource ? JSON.stringify(datasource) : '',
35
+ 'data-layout': layout,
36
+ 'data-width': "".concat(width),
37
+ class: 'blockCardView-content-wrap'
38
+ };
39
+ return ['div', attrs, ['a', {
40
+ // To match `packages/linking-platform/smart-card/src/view/CardWithUrl/component-lazy/LoadingCardLink.tsx`
41
+ // Which uses frame styling `packages/linking-platform/smart-card/src/view/InlineCard/Frame/styled.ts`
42
+ style: (0, _lazyNodeView.convertToInlineCss)({
43
+ marginLeft: "var(--ds-space-negative-025, -2px)",
44
+ boxDecorationBreak: 'clone',
45
+ WebkitBoxDecorationBreak: 'clone',
46
+ padding: "var(--ds-space-025, 2px)".concat(" 0px"),
47
+ lineHeight: '22px'
48
+ }),
49
+ href: url || ''
50
+ }, (node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.url) || ' ']];
51
+ }
52
+ });
53
+ };
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.embedCardSpecWithFixedToDOM = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _adfSchema = require("@atlaskit/adf-schema");
10
+ var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
11
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
12
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
13
+ 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; }
14
+ 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) { (0, _defineProperty2.default)(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; } /**
15
+ * Some of these functions and styling are duplicated from their custom node view equivalents
16
+ *
17
+ * WHY?
18
+ * This will eventually move to `@atlaskit/adf-schema` and we cannot reference
19
+ * `@atlaskit/editor-common` from here or it will cause dependency issues.
20
+ *
21
+ * In the long term likely `toDOM` will move back out of `adf-schema` in which
22
+ * case we can consolidate them.
23
+ */
24
+ // From `packages/editor/editor-common/src/ui/MediaSingle/styled.tsx`
25
+ function calcMargin(layout) {
26
+ switch (layout) {
27
+ case 'wrap-right':
28
+ return '12px auto 12px 12px';
29
+ case 'wrap-left':
30
+ return '12px 12px 12px auto';
31
+ default:
32
+ return '24px auto';
33
+ }
34
+ }
35
+
36
+ // From `packages/editor/editor-common/src/ui/MediaSingle/styled.tsx`
37
+ function float(layout) {
38
+ switch (layout) {
39
+ case 'wrap-right':
40
+ return 'right';
41
+ case 'wrap-left':
42
+ return 'left';
43
+ default:
44
+ return 'none';
45
+ }
46
+ }
47
+
48
+ // From `packages/editor/editor-common/src/media-single/constants.ts`
49
+ var MEDIA_SINGLE_GUTTER_SIZE = 24;
50
+
51
+ // From `packages/editor/editor-common/src/ui/MediaSingle/styled.tsx`
52
+ function calcPxFromPct(pct, lineLength) {
53
+ var maxWidth = lineLength + MEDIA_SINGLE_GUTTER_SIZE;
54
+ return maxWidth * pct - MEDIA_SINGLE_GUTTER_SIZE;
55
+ }
56
+
57
+ // ED-24488: We can't retrieve the editor width from here easily.
58
+ // For now we're using the default line length here, but this will be
59
+ // incorrect on smaller devices.
60
+ var LINE_LENGTH = 760;
61
+
62
+ // @nodeSpecException:toDOM patch
63
+ var embedCardSpecWithFixedToDOM = exports.embedCardSpecWithFixedToDOM = function embedCardSpecWithFixedToDOM() {
64
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_lazy-node-views')) {
65
+ return _adfSchema.embedCard;
66
+ }
67
+ return _objectSpread(_objectSpread({}, _adfSchema.embedCard), {}, {
68
+ toDOM: function toDOM(node) {
69
+ var _node$attrs = node.attrs,
70
+ url = _node$attrs.url,
71
+ layout = _node$attrs.layout,
72
+ width = _node$attrs.width,
73
+ originalWidth = _node$attrs.originalWidth,
74
+ originalHeight = _node$attrs.originalHeight;
75
+ var aspectRatio = originalWidth && originalHeight ? originalWidth / originalHeight : _editorSharedStyles.DEFAULT_EMBED_CARD_WIDTH / _editorSharedStyles.DEFAULT_EMBED_CARD_HEIGHT;
76
+ var attrs = {
77
+ 'data-embed-card': '',
78
+ 'data-card-url': url,
79
+ 'data-layout': layout,
80
+ 'data-width': width,
81
+ 'data-original-width': originalWidth,
82
+ 'data-original-height': originalHeight,
83
+ class: 'embedCardView-content-wrap',
84
+ // From `packages/editor/editor-plugin-card/src/ui/ResizableEmbedCard.tsx`
85
+ style: (0, _lazyNodeView.convertToInlineCss)({
86
+ margin: calcMargin(layout),
87
+ width: "".concat(Math.ceil(calcPxFromPct(width / 100, LINE_LENGTH)), "px"),
88
+ marginRight: layout === 'align-end' ? '0' : '',
89
+ marginLeft: layout === 'align-start' ? '0' : '',
90
+ float: float(layout)
91
+ })
92
+ };
93
+ return ['div', attrs,
94
+ // This is the only modification to the embed card `toDOM`
95
+ // This is to match the behaviour of Card which lazy loads
96
+ // and uses just a URL as a fallback
97
+ //
98
+ // To match: `packages/linking-platform/smart-card/src/view/CardWithUrl/component-lazy/LoadingCardLink.tsx`
99
+ ['a', {
100
+ style: (0, _lazyNodeView.convertToInlineCss)({
101
+ marginLeft: "var(--ds-space-negative-025, -2px)",
102
+ boxDecorationBreak: 'clone',
103
+ WebkitBoxDecorationBreak: 'clone',
104
+ padding: "var(--ds-space-025, 2px)".concat(" 0px"),
105
+ lineHeight: '22px'
106
+ })
107
+ }, url !== null && url !== void 0 ? url : ''],
108
+ // From `packages/editor/editor-plugin-card/src/ui/ResizableEmbedCard.tsx`
109
+ // The `getHeightDefiningComponent` that defines the height of the element
110
+ ['span', {
111
+ style: (0, _lazyNodeView.convertToInlineCss)({
112
+ display: 'block',
113
+ paddingBottom: "calc(".concat((1 / aspectRatio * 100).toFixed(3), "% + ", "var(--ds-space-400, 32px)", ")")
114
+ })
115
+ }]];
116
+ }
117
+ });
118
+ };
@@ -4,9 +4,10 @@ import PropTypes from 'prop-types';
4
4
  import rafSchedule from 'raf-schd';
5
5
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
6
6
  import { findOverflowScrollParent, UnsupportedBlock } from '@atlaskit/editor-common/ui';
7
- import { browser } from '@atlaskit/editor-common/utils';
7
+ import { browser, canRenderDatasource } from '@atlaskit/editor-common/utils';
8
8
  import { fg } from '@atlaskit/platform-feature-flags';
9
9
  import { Card as SmartCard } from '@atlaskit/smart-card';
10
+ import { Datasource } from '../nodeviews/datasource';
10
11
  import { registerCard } from '../pm-plugins/actions';
11
12
  import { isDatasourceNode } from '../utils';
12
13
  import { Card } from './genericCard';
@@ -168,4 +169,47 @@ export class BlockCard extends ReactNodeView {
168
169
  var _this$unsubscribe;
169
170
  (_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 ? void 0 : _this$unsubscribe.call(this);
170
171
  }
171
- }
172
+ }
173
+ export const blockCardNodeView = ({
174
+ pmPluginFactoryParams,
175
+ platform,
176
+ actionOptions,
177
+ showServerActions,
178
+ pluginInjectionApi,
179
+ onClickCallback,
180
+ allowDatasource,
181
+ inlineCardViewProducer
182
+ }) => (node, view, getPos, decorations) => {
183
+ const {
184
+ portalProviderAPI,
185
+ eventDispatcher
186
+ } = pmPluginFactoryParams;
187
+ const reactComponentProps = {
188
+ platform,
189
+ actionOptions,
190
+ showServerActions,
191
+ pluginInjectionApi,
192
+ onClickCallback: onClickCallback
193
+ };
194
+ const isDatasource = isDatasourceNode(node);
195
+ if (isDatasource) {
196
+ var _node$attrs, _node$attrs$datasourc;
197
+ if (allowDatasource && platform !== 'mobile' && canRenderDatasource(node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : (_node$attrs$datasourc = _node$attrs.datasource) === null || _node$attrs$datasourc === void 0 ? void 0 : _node$attrs$datasourc.id)) {
198
+ const datasourcePosition = typeof getPos === 'function' && getPos();
199
+ const datasourceResolvedPosition = datasourcePosition && view.state.doc.resolve(datasourcePosition);
200
+ const isNodeNested = !!(datasourceResolvedPosition && datasourceResolvedPosition.depth > 0);
201
+ return new Datasource({
202
+ node,
203
+ view,
204
+ getPos,
205
+ portalProviderAPI,
206
+ eventDispatcher,
207
+ pluginInjectionApi,
208
+ isNodeNested
209
+ }).init();
210
+ } else {
211
+ return inlineCardViewProducer(node, view, getPos, decorations);
212
+ }
213
+ }
214
+ return new BlockCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
215
+ };
@@ -391,4 +391,32 @@ export class EmbedCard extends ReactNodeView {
391
391
  var _this$unsubscribe;
392
392
  (_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 ? void 0 : _this$unsubscribe.call(this);
393
393
  }
394
- }
394
+ }
395
+ export const embedCardNodeView = ({
396
+ allowResizing,
397
+ platform,
398
+ fullWidthMode,
399
+ pmPluginFactoryParams,
400
+ pluginInjectionApi,
401
+ actionOptions,
402
+ showServerActions,
403
+ onClickCallback
404
+ }) => (node, view, getPos) => {
405
+ const {
406
+ portalProviderAPI,
407
+ eventDispatcher,
408
+ dispatchAnalyticsEvent
409
+ } = pmPluginFactoryParams;
410
+ const reactComponentProps = {
411
+ eventDispatcher,
412
+ allowResizing,
413
+ platform,
414
+ fullWidthMode,
415
+ dispatchAnalyticsEvent,
416
+ pluginInjectionApi,
417
+ actionOptions,
418
+ showServerActions,
419
+ onClickCallback: onClickCallback
420
+ };
421
+ return new EmbedCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
422
+ };
@@ -0,0 +1,21 @@
1
+ import { withLazyLoading } from '@atlaskit/editor-common/lazy-node-view';
2
+ import { fg } from '@atlaskit/platform-feature-flags';
3
+ import { blockCardNodeView } from './blockCard';
4
+ export const lazyBlockCardView = props => {
5
+ if (!fg('platform_editor_lazy-node-views')) {
6
+ return blockCardNodeView(props);
7
+ }
8
+ return withLazyLoading({
9
+ nodeName: 'blockCard',
10
+ getNodeViewOptions: () => {},
11
+ loader: () => {
12
+ const result = import( /* webpackChunkName: "@atlaskit-internal_editor-plugin-tasks-and-decisions_task-item-nodeview" */
13
+ './blockCard').then(({
14
+ blockCardNodeView
15
+ }) => {
16
+ return blockCardNodeView(props);
17
+ });
18
+ return result;
19
+ }
20
+ });
21
+ };