@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
@@ -0,0 +1,21 @@
1
+ import { withLazyLoading } from '@atlaskit/editor-common/lazy-node-view';
2
+ import { fg } from '@atlaskit/platform-feature-flags';
3
+ import { embedCardNodeView } from './embedCard';
4
+ export const lazyEmbedCardView = props => {
5
+ if (!fg('platform_editor_lazy-node-views')) {
6
+ return embedCardNodeView(props);
7
+ }
8
+ return withLazyLoading({
9
+ nodeName: 'embedCard',
10
+ getNodeViewOptions: () => {},
11
+ loader: () => {
12
+ const result = import( /* webpackChunkName: "@atlaskit-internal_editor-plugin-embed-card-item-nodeview" */
13
+ './embedCard').then(({
14
+ embedCardNodeView
15
+ }) => {
16
+ return embedCardNodeView(props);
17
+ });
18
+ return result;
19
+ }
20
+ });
21
+ };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { blockCard, embedCard, inlineCard } from '@atlaskit/adf-schema';
2
+ import { inlineCard } from '@atlaskit/adf-schema';
3
3
  import { cardMessages as messages } from '@atlaskit/editor-common/messages';
4
4
  import { IconDatasourceAssetsObjects, IconDatasourceConfluenceSearch, IconDatasourceJiraIssue } from '@atlaskit/editor-common/quick-insert';
5
5
  import { canRenderDatasource } from '@atlaskit/editor-common/utils';
@@ -10,6 +10,8 @@ import { queueCardsFromChangedTr } from './pm-plugins/doc';
10
10
  import { cardKeymap } from './pm-plugins/keymap';
11
11
  import { createPlugin } from './pm-plugins/main';
12
12
  import { pluginKey } from './pm-plugins/plugin-key';
13
+ import { blockCardSpecWithFixedToDOM } from './toDOM-fixes/blockCard';
14
+ import { embedCardSpecWithFixedToDOM } from './toDOM-fixes/embedCard';
13
15
  import { floatingToolbar, getEndingToolbarItems, getStartingToolbarItems } from './toolbar';
14
16
  import DatasourceModalWithState from './ui/DatasourceModal/ModalWithState';
15
17
  import { EditorLinkingPlatformAnalytics } from './ui/EditorLinkingPlatformAnalytics';
@@ -36,12 +38,12 @@ export const cardPlugin = ({
36
38
  node: inlineCard
37
39
  }, {
38
40
  name: 'blockCard',
39
- node: blockCard
41
+ node: blockCardSpecWithFixedToDOM()
40
42
  }];
41
43
  if (options.allowEmbeds) {
42
44
  nodes.push({
43
45
  name: 'embedCard',
44
- node: embedCard
46
+ node: embedCardSpecWithFixedToDOM()
45
47
  });
46
48
  }
47
49
  return nodes;
@@ -2,19 +2,17 @@ import rafSchedule from 'raf-schd';
2
2
  import { getInlineNodeViewProducer } from '@atlaskit/editor-common/react-node-view';
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import { DATASOURCE_INNER_CONTAINER_CLASSNAME } from '@atlaskit/editor-common/styles';
5
- import { canRenderDatasource } from '@atlaskit/editor-common/utils';
6
5
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
7
6
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
8
7
  import { DATASOURCE_DEFAULT_LAYOUT } from '@atlaskit/linking-common';
9
8
  import { fg } from '@atlaskit/platform-feature-flags';
10
9
  import { eventsFromTransaction } from '../analytics/events-from-tr';
11
10
  import { isLocalStorageKeyDiscovered } from '../common/local-storage';
12
- import { BlockCard } from '../nodeviews/blockCard';
13
- import { Datasource } from '../nodeviews/datasource';
14
- import { EmbedCard } from '../nodeviews/embedCard';
15
11
  import { InlineCardNodeView } from '../nodeviews/inlineCard';
12
+ import { lazyBlockCardView } from '../nodeviews/lazy-block-card';
13
+ import { lazyEmbedCardView } from '../nodeviews/lazy-embed-card';
16
14
  import { isDatasourceTableLayout } from '../ui/LayoutButton/utils';
17
- import { isBlockSupportedAtPosition, isDatasourceNode, isEmbedSupportedAtPosition } from '../utils';
15
+ import { isBlockSupportedAtPosition, isEmbedSupportedAtPosition } from '../utils';
18
16
  import { clearOverlayCandidate, setCardLayoutAndDatasourceTableRef, setDatasourceTableRef } from './actions';
19
17
  import { pluginKey } from './plugin-key';
20
18
  import reducer from './reducers';
@@ -246,59 +244,26 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
246
244
  props: {
247
245
  nodeViews: {
248
246
  inlineCard: inlineCardViewProducer,
249
- blockCard: (node, view, getPos, decorations) => {
250
- const {
251
- portalProviderAPI,
252
- eventDispatcher
253
- } = pmPluginFactoryParams;
254
- const reactComponentProps = {
255
- platform,
256
- actionOptions,
257
- showServerActions,
258
- pluginInjectionApi,
259
- onClickCallback: options.onClickCallback
260
- };
261
- const isDatasource = isDatasourceNode(node);
262
- if (isDatasource) {
263
- var _node$attrs2, _node$attrs2$datasour;
264
- if (options.allowDatasource && platform !== 'mobile' && canRenderDatasource(node === null || node === void 0 ? void 0 : (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : (_node$attrs2$datasour = _node$attrs2.datasource) === null || _node$attrs2$datasour === void 0 ? void 0 : _node$attrs2$datasour.id)) {
265
- const datasourcePosition = typeof getPos === 'function' && getPos();
266
- const datasourceResolvedPosition = datasourcePosition && view.state.doc.resolve(datasourcePosition);
267
- const isNodeNested = !!(datasourceResolvedPosition && datasourceResolvedPosition.depth > 0);
268
- return new Datasource({
269
- node,
270
- view,
271
- getPos,
272
- portalProviderAPI,
273
- eventDispatcher,
274
- pluginInjectionApi,
275
- isNodeNested
276
- }).init();
277
- } else {
278
- return inlineCardViewProducer(node, view, getPos, decorations);
279
- }
280
- }
281
- return new BlockCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
282
- },
283
- embedCard: (node, view, getPos) => {
284
- const {
285
- portalProviderAPI,
286
- eventDispatcher,
287
- dispatchAnalyticsEvent
288
- } = pmPluginFactoryParams;
289
- const reactComponentProps = {
290
- eventDispatcher,
291
- allowResizing,
292
- platform,
293
- fullWidthMode,
294
- dispatchAnalyticsEvent,
295
- pluginInjectionApi,
296
- actionOptions,
297
- showServerActions,
298
- onClickCallback: options.onClickCallback
299
- };
300
- return new EmbedCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
301
- }
247
+ blockCard: lazyBlockCardView({
248
+ pmPluginFactoryParams,
249
+ platform,
250
+ actionOptions,
251
+ showServerActions,
252
+ pluginInjectionApi,
253
+ onClickCallback,
254
+ allowDatasource: options.allowDatasource,
255
+ inlineCardViewProducer
256
+ }),
257
+ embedCard: lazyEmbedCardView({
258
+ allowResizing,
259
+ platform,
260
+ fullWidthMode,
261
+ pmPluginFactoryParams,
262
+ pluginInjectionApi,
263
+ actionOptions,
264
+ showServerActions,
265
+ onClickCallback: options.onClickCallback
266
+ })
302
267
  },
303
268
  ...(enableInlineUpgradeFeatures && {
304
269
  handleKeyDown: view => {
@@ -0,0 +1,47 @@
1
+ import { blockCard } from '@atlaskit/adf-schema';
2
+ import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
4
+ // @nodeSpecException:toDOM patch
5
+ export const blockCardSpecWithFixedToDOM = () => {
6
+ if (!fg('platform_editor_lazy-node-views')) {
7
+ return blockCard;
8
+ }
9
+ return {
10
+ ...blockCard,
11
+ toDOM: node => {
12
+ var _node$attrs;
13
+ const {
14
+ url
15
+ } = node.attrs;
16
+ const {
17
+ data
18
+ } = node.attrs;
19
+ const {
20
+ layout,
21
+ width,
22
+ datasource
23
+ } = node.attrs;
24
+ const attrs = {
25
+ 'data-block-card': '',
26
+ 'data-card-url': url || '',
27
+ 'data-card-data': data ? JSON.stringify(data) : '',
28
+ 'data-datasource': datasource ? JSON.stringify(datasource) : '',
29
+ 'data-layout': layout,
30
+ 'data-width': `${width}`,
31
+ class: 'blockCardView-content-wrap'
32
+ };
33
+ return ['div', attrs, ['a', {
34
+ // To match `packages/linking-platform/smart-card/src/view/CardWithUrl/component-lazy/LoadingCardLink.tsx`
35
+ // Which uses frame styling `packages/linking-platform/smart-card/src/view/InlineCard/Frame/styled.ts`
36
+ style: convertToInlineCss({
37
+ marginLeft: "var(--ds-space-negative-025, -2px)",
38
+ boxDecorationBreak: 'clone',
39
+ WebkitBoxDecorationBreak: 'clone',
40
+ padding: `${"var(--ds-space-025, 2px)"} 0px`,
41
+ lineHeight: '22px'
42
+ }),
43
+ href: url || ''
44
+ }, (node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.url) || ' ']];
45
+ }
46
+ };
47
+ };
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Some of these functions and styling are duplicated from their custom node view equivalents
3
+ *
4
+ * WHY?
5
+ * This will eventually move to `@atlaskit/adf-schema` and we cannot reference
6
+ * `@atlaskit/editor-common` from here or it will cause dependency issues.
7
+ *
8
+ * In the long term likely `toDOM` will move back out of `adf-schema` in which
9
+ * case we can consolidate them.
10
+ */
11
+ import { embedCard } from '@atlaskit/adf-schema';
12
+ import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
13
+ import { DEFAULT_EMBED_CARD_HEIGHT, DEFAULT_EMBED_CARD_WIDTH } from '@atlaskit/editor-shared-styles';
14
+ import { fg } from '@atlaskit/platform-feature-flags';
15
+ // From `packages/editor/editor-common/src/ui/MediaSingle/styled.tsx`
16
+ function calcMargin(layout) {
17
+ switch (layout) {
18
+ case 'wrap-right':
19
+ return '12px auto 12px 12px';
20
+ case 'wrap-left':
21
+ return '12px 12px 12px auto';
22
+ default:
23
+ return '24px auto';
24
+ }
25
+ }
26
+
27
+ // From `packages/editor/editor-common/src/ui/MediaSingle/styled.tsx`
28
+ function float(layout) {
29
+ switch (layout) {
30
+ case 'wrap-right':
31
+ return 'right';
32
+ case 'wrap-left':
33
+ return 'left';
34
+ default:
35
+ return 'none';
36
+ }
37
+ }
38
+
39
+ // From `packages/editor/editor-common/src/media-single/constants.ts`
40
+ const MEDIA_SINGLE_GUTTER_SIZE = 24;
41
+
42
+ // From `packages/editor/editor-common/src/ui/MediaSingle/styled.tsx`
43
+ function calcPxFromPct(pct, lineLength) {
44
+ const maxWidth = lineLength + MEDIA_SINGLE_GUTTER_SIZE;
45
+ return maxWidth * pct - MEDIA_SINGLE_GUTTER_SIZE;
46
+ }
47
+
48
+ // ED-24488: We can't retrieve the editor width from here easily.
49
+ // For now we're using the default line length here, but this will be
50
+ // incorrect on smaller devices.
51
+ const LINE_LENGTH = 760;
52
+
53
+ // @nodeSpecException:toDOM patch
54
+ export const embedCardSpecWithFixedToDOM = () => {
55
+ if (!fg('platform_editor_lazy-node-views')) {
56
+ return embedCard;
57
+ }
58
+ return {
59
+ ...embedCard,
60
+ toDOM: node => {
61
+ const {
62
+ url,
63
+ layout,
64
+ width,
65
+ originalWidth,
66
+ originalHeight
67
+ } = node.attrs;
68
+ const aspectRatio = originalWidth && originalHeight ? originalWidth / originalHeight : DEFAULT_EMBED_CARD_WIDTH / DEFAULT_EMBED_CARD_HEIGHT;
69
+ const attrs = {
70
+ 'data-embed-card': '',
71
+ 'data-card-url': url,
72
+ 'data-layout': layout,
73
+ 'data-width': width,
74
+ 'data-original-width': originalWidth,
75
+ 'data-original-height': originalHeight,
76
+ class: 'embedCardView-content-wrap',
77
+ // From `packages/editor/editor-plugin-card/src/ui/ResizableEmbedCard.tsx`
78
+ style: convertToInlineCss({
79
+ margin: calcMargin(layout),
80
+ width: `${Math.ceil(calcPxFromPct(width / 100, LINE_LENGTH))}px`,
81
+ marginRight: layout === 'align-end' ? '0' : '',
82
+ marginLeft: layout === 'align-start' ? '0' : '',
83
+ float: float(layout)
84
+ })
85
+ };
86
+ return ['div', attrs,
87
+ // This is the only modification to the embed card `toDOM`
88
+ // This is to match the behaviour of Card which lazy loads
89
+ // and uses just a URL as a fallback
90
+ //
91
+ // To match: `packages/linking-platform/smart-card/src/view/CardWithUrl/component-lazy/LoadingCardLink.tsx`
92
+ ['a', {
93
+ style: convertToInlineCss({
94
+ marginLeft: "var(--ds-space-negative-025, -2px)",
95
+ boxDecorationBreak: 'clone',
96
+ WebkitBoxDecorationBreak: 'clone',
97
+ padding: `${"var(--ds-space-025, 2px)"} 0px`,
98
+ lineHeight: '22px'
99
+ })
100
+ }, url !== null && url !== void 0 ? url : ''],
101
+ // From `packages/editor/editor-plugin-card/src/ui/ResizableEmbedCard.tsx`
102
+ // The `getHeightDefiningComponent` that defines the height of the element
103
+ ['span', {
104
+ style: convertToInlineCss({
105
+ display: 'block',
106
+ paddingBottom: `calc(${(1 / aspectRatio * 100).toFixed(3)}% + ${"var(--ds-space-400, 32px)"})`
107
+ })
108
+ }]];
109
+ }
110
+ };
111
+ };
@@ -13,9 +13,10 @@ import PropTypes from 'prop-types';
13
13
  import rafSchedule from 'raf-schd';
14
14
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
15
15
  import { findOverflowScrollParent, UnsupportedBlock } from '@atlaskit/editor-common/ui';
16
- import { browser } from '@atlaskit/editor-common/utils';
16
+ import { browser, canRenderDatasource } from '@atlaskit/editor-common/utils';
17
17
  import { fg } from '@atlaskit/platform-feature-flags';
18
18
  import { Card as SmartCard } from '@atlaskit/smart-card';
19
+ import { Datasource } from '../nodeviews/datasource';
19
20
  import { registerCard } from '../pm-plugins/actions';
20
21
  import { isDatasourceNode } from '../utils';
21
22
  import { Card } from './genericCard';
@@ -205,4 +206,46 @@ export var BlockCard = /*#__PURE__*/function (_ReactNodeView) {
205
206
  }
206
207
  }]);
207
208
  return BlockCard;
208
- }(ReactNodeView);
209
+ }(ReactNodeView);
210
+ export var blockCardNodeView = function blockCardNodeView(_ref3) {
211
+ var pmPluginFactoryParams = _ref3.pmPluginFactoryParams,
212
+ platform = _ref3.platform,
213
+ actionOptions = _ref3.actionOptions,
214
+ showServerActions = _ref3.showServerActions,
215
+ pluginInjectionApi = _ref3.pluginInjectionApi,
216
+ onClickCallback = _ref3.onClickCallback,
217
+ allowDatasource = _ref3.allowDatasource,
218
+ inlineCardViewProducer = _ref3.inlineCardViewProducer;
219
+ return function (node, view, getPos, decorations) {
220
+ var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
221
+ eventDispatcher = pmPluginFactoryParams.eventDispatcher;
222
+ var reactComponentProps = {
223
+ platform: platform,
224
+ actionOptions: actionOptions,
225
+ showServerActions: showServerActions,
226
+ pluginInjectionApi: pluginInjectionApi,
227
+ onClickCallback: onClickCallback
228
+ };
229
+ var isDatasource = isDatasourceNode(node);
230
+ if (isDatasource) {
231
+ var _node$attrs2;
232
+ if (allowDatasource && platform !== 'mobile' && 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)) {
233
+ var datasourcePosition = typeof getPos === 'function' && getPos();
234
+ var datasourceResolvedPosition = datasourcePosition && view.state.doc.resolve(datasourcePosition);
235
+ var isNodeNested = !!(datasourceResolvedPosition && datasourceResolvedPosition.depth > 0);
236
+ return new Datasource({
237
+ node: node,
238
+ view: view,
239
+ getPos: getPos,
240
+ portalProviderAPI: portalProviderAPI,
241
+ eventDispatcher: eventDispatcher,
242
+ pluginInjectionApi: pluginInjectionApi,
243
+ isNodeNested: isNodeNested
244
+ }).init();
245
+ } else {
246
+ return inlineCardViewProducer(node, view, getPos, decorations);
247
+ }
248
+ }
249
+ return new BlockCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
250
+ };
251
+ };
@@ -416,4 +416,31 @@ export var EmbedCard = /*#__PURE__*/function (_ReactNodeView) {
416
416
  }
417
417
  }]);
418
418
  return EmbedCard;
419
- }(ReactNodeView);
419
+ }(ReactNodeView);
420
+ export var embedCardNodeView = function embedCardNodeView(_ref4) {
421
+ var allowResizing = _ref4.allowResizing,
422
+ platform = _ref4.platform,
423
+ fullWidthMode = _ref4.fullWidthMode,
424
+ pmPluginFactoryParams = _ref4.pmPluginFactoryParams,
425
+ pluginInjectionApi = _ref4.pluginInjectionApi,
426
+ actionOptions = _ref4.actionOptions,
427
+ showServerActions = _ref4.showServerActions,
428
+ onClickCallback = _ref4.onClickCallback;
429
+ return function (node, view, getPos) {
430
+ var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
431
+ eventDispatcher = pmPluginFactoryParams.eventDispatcher,
432
+ dispatchAnalyticsEvent = pmPluginFactoryParams.dispatchAnalyticsEvent;
433
+ var reactComponentProps = {
434
+ eventDispatcher: eventDispatcher,
435
+ allowResizing: allowResizing,
436
+ platform: platform,
437
+ fullWidthMode: fullWidthMode,
438
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
439
+ pluginInjectionApi: pluginInjectionApi,
440
+ actionOptions: actionOptions,
441
+ showServerActions: showServerActions,
442
+ onClickCallback: onClickCallback
443
+ };
444
+ return new EmbedCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
445
+ };
446
+ };
@@ -0,0 +1,20 @@
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 var lazyBlockCardView = function lazyBlockCardView(props) {
5
+ if (!fg('platform_editor_lazy-node-views')) {
6
+ return blockCardNodeView(props);
7
+ }
8
+ return withLazyLoading({
9
+ nodeName: 'blockCard',
10
+ getNodeViewOptions: function getNodeViewOptions() {},
11
+ loader: function loader() {
12
+ var result = import( /* webpackChunkName: "@atlaskit-internal_editor-plugin-tasks-and-decisions_task-item-nodeview" */
13
+ './blockCard').then(function (_ref) {
14
+ var blockCardNodeView = _ref.blockCardNodeView;
15
+ return blockCardNodeView(props);
16
+ });
17
+ return result;
18
+ }
19
+ });
20
+ };
@@ -0,0 +1,20 @@
1
+ import { withLazyLoading } from '@atlaskit/editor-common/lazy-node-view';
2
+ import { fg } from '@atlaskit/platform-feature-flags';
3
+ import { embedCardNodeView } from './embedCard';
4
+ export var lazyEmbedCardView = function lazyEmbedCardView(props) {
5
+ if (!fg('platform_editor_lazy-node-views')) {
6
+ return embedCardNodeView(props);
7
+ }
8
+ return withLazyLoading({
9
+ nodeName: 'embedCard',
10
+ getNodeViewOptions: function getNodeViewOptions() {},
11
+ loader: function loader() {
12
+ var result = import( /* webpackChunkName: "@atlaskit-internal_editor-plugin-embed-card-item-nodeview" */
13
+ './embedCard').then(function (_ref) {
14
+ var embedCardNodeView = _ref.embedCardNodeView;
15
+ return embedCardNodeView(props);
16
+ });
17
+ return result;
18
+ }
19
+ });
20
+ };
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  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; }
3
3
  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; }
4
4
  import React from 'react';
5
- import { blockCard, embedCard, inlineCard } from '@atlaskit/adf-schema';
5
+ import { inlineCard } from '@atlaskit/adf-schema';
6
6
  import { cardMessages as messages } from '@atlaskit/editor-common/messages';
7
7
  import { IconDatasourceAssetsObjects, IconDatasourceConfluenceSearch, IconDatasourceJiraIssue } from '@atlaskit/editor-common/quick-insert';
8
8
  import { canRenderDatasource } from '@atlaskit/editor-common/utils';
@@ -13,6 +13,8 @@ import { queueCardsFromChangedTr } from './pm-plugins/doc';
13
13
  import { cardKeymap } from './pm-plugins/keymap';
14
14
  import { createPlugin } from './pm-plugins/main';
15
15
  import { pluginKey } from './pm-plugins/plugin-key';
16
+ import { blockCardSpecWithFixedToDOM } from './toDOM-fixes/blockCard';
17
+ import { embedCardSpecWithFixedToDOM } from './toDOM-fixes/embedCard';
16
18
  import { floatingToolbar, getEndingToolbarItems, getStartingToolbarItems } from './toolbar';
17
19
  import DatasourceModalWithState from './ui/DatasourceModal/ModalWithState';
18
20
  import { EditorLinkingPlatformAnalytics } from './ui/EditorLinkingPlatformAnalytics';
@@ -38,12 +40,12 @@ export var cardPlugin = function cardPlugin(_ref) {
38
40
  node: inlineCard
39
41
  }, {
40
42
  name: 'blockCard',
41
- node: blockCard
43
+ node: blockCardSpecWithFixedToDOM()
42
44
  }];
43
45
  if (options.allowEmbeds) {
44
46
  nodes.push({
45
47
  name: 'embedCard',
46
- node: embedCard
48
+ node: embedCardSpecWithFixedToDOM()
47
49
  });
48
50
  }
49
51
  return nodes;
@@ -6,19 +6,17 @@ import rafSchedule from 'raf-schd';
6
6
  import { getInlineNodeViewProducer } from '@atlaskit/editor-common/react-node-view';
7
7
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
8
8
  import { DATASOURCE_INNER_CONTAINER_CLASSNAME } from '@atlaskit/editor-common/styles';
9
- import { canRenderDatasource } from '@atlaskit/editor-common/utils';
10
9
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
11
10
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
12
11
  import { DATASOURCE_DEFAULT_LAYOUT } from '@atlaskit/linking-common';
13
12
  import { fg } from '@atlaskit/platform-feature-flags';
14
13
  import { eventsFromTransaction } from '../analytics/events-from-tr';
15
14
  import { isLocalStorageKeyDiscovered } from '../common/local-storage';
16
- import { BlockCard } from '../nodeviews/blockCard';
17
- import { Datasource } from '../nodeviews/datasource';
18
- import { EmbedCard } from '../nodeviews/embedCard';
19
15
  import { InlineCardNodeView } from '../nodeviews/inlineCard';
16
+ import { lazyBlockCardView } from '../nodeviews/lazy-block-card';
17
+ import { lazyEmbedCardView } from '../nodeviews/lazy-embed-card';
20
18
  import { isDatasourceTableLayout } from '../ui/LayoutButton/utils';
21
- import { isBlockSupportedAtPosition, isDatasourceNode, isEmbedSupportedAtPosition } from '../utils';
19
+ import { isBlockSupportedAtPosition, isEmbedSupportedAtPosition } from '../utils';
22
20
  import { clearOverlayCandidate, setCardLayoutAndDatasourceTableRef, setDatasourceTableRef } from './actions';
23
21
  import { pluginKey } from './plugin-key';
24
22
  import reducer from './reducers';
@@ -242,55 +240,26 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
242
240
  props: _objectSpread({
243
241
  nodeViews: {
244
242
  inlineCard: inlineCardViewProducer,
245
- blockCard: function blockCard(node, view, getPos, decorations) {
246
- var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
247
- eventDispatcher = pmPluginFactoryParams.eventDispatcher;
248
- var reactComponentProps = {
249
- platform: platform,
250
- actionOptions: actionOptions,
251
- showServerActions: showServerActions,
252
- pluginInjectionApi: pluginInjectionApi,
253
- onClickCallback: options.onClickCallback
254
- };
255
- var isDatasource = isDatasourceNode(node);
256
- if (isDatasource) {
257
- var _node$attrs2;
258
- if (options.allowDatasource && platform !== 'mobile' && 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)) {
259
- var datasourcePosition = typeof getPos === 'function' && getPos();
260
- var datasourceResolvedPosition = datasourcePosition && view.state.doc.resolve(datasourcePosition);
261
- var isNodeNested = !!(datasourceResolvedPosition && datasourceResolvedPosition.depth > 0);
262
- return new Datasource({
263
- node: node,
264
- view: view,
265
- getPos: getPos,
266
- portalProviderAPI: portalProviderAPI,
267
- eventDispatcher: eventDispatcher,
268
- pluginInjectionApi: pluginInjectionApi,
269
- isNodeNested: isNodeNested
270
- }).init();
271
- } else {
272
- return inlineCardViewProducer(node, view, getPos, decorations);
273
- }
274
- }
275
- return new BlockCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
276
- },
277
- embedCard: function embedCard(node, view, getPos) {
278
- var portalProviderAPI = pmPluginFactoryParams.portalProviderAPI,
279
- eventDispatcher = pmPluginFactoryParams.eventDispatcher,
280
- dispatchAnalyticsEvent = pmPluginFactoryParams.dispatchAnalyticsEvent;
281
- var reactComponentProps = {
282
- eventDispatcher: eventDispatcher,
283
- allowResizing: allowResizing,
284
- platform: platform,
285
- fullWidthMode: fullWidthMode,
286
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
287
- pluginInjectionApi: pluginInjectionApi,
288
- actionOptions: actionOptions,
289
- showServerActions: showServerActions,
290
- onClickCallback: options.onClickCallback
291
- };
292
- return new EmbedCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined).init();
293
- }
243
+ blockCard: lazyBlockCardView({
244
+ pmPluginFactoryParams: pmPluginFactoryParams,
245
+ platform: platform,
246
+ actionOptions: actionOptions,
247
+ showServerActions: showServerActions,
248
+ pluginInjectionApi: pluginInjectionApi,
249
+ onClickCallback: onClickCallback,
250
+ allowDatasource: options.allowDatasource,
251
+ inlineCardViewProducer: inlineCardViewProducer
252
+ }),
253
+ embedCard: lazyEmbedCardView({
254
+ allowResizing: allowResizing,
255
+ platform: platform,
256
+ fullWidthMode: fullWidthMode,
257
+ pmPluginFactoryParams: pmPluginFactoryParams,
258
+ pluginInjectionApi: pluginInjectionApi,
259
+ actionOptions: actionOptions,
260
+ showServerActions: showServerActions,
261
+ onClickCallback: options.onClickCallback
262
+ })
294
263
  }
295
264
  }, enableInlineUpgradeFeatures && {
296
265
  handleKeyDown: function handleKeyDown(view) {
@@ -0,0 +1,46 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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; }
4
+ import { blockCard } from '@atlaskit/adf-schema';
5
+ import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
6
+ import { fg } from '@atlaskit/platform-feature-flags';
7
+ // @nodeSpecException:toDOM patch
8
+ export var blockCardSpecWithFixedToDOM = function blockCardSpecWithFixedToDOM() {
9
+ if (!fg('platform_editor_lazy-node-views')) {
10
+ return blockCard;
11
+ }
12
+ return _objectSpread(_objectSpread({}, blockCard), {}, {
13
+ toDOM: function toDOM(node) {
14
+ var _node$attrs;
15
+ var _ref = node.attrs,
16
+ url = _ref.url;
17
+ var _ref2 = node.attrs,
18
+ data = _ref2.data;
19
+ var _ref3 = node.attrs,
20
+ layout = _ref3.layout,
21
+ width = _ref3.width,
22
+ datasource = _ref3.datasource;
23
+ var attrs = {
24
+ 'data-block-card': '',
25
+ 'data-card-url': url || '',
26
+ 'data-card-data': data ? JSON.stringify(data) : '',
27
+ 'data-datasource': datasource ? JSON.stringify(datasource) : '',
28
+ 'data-layout': layout,
29
+ 'data-width': "".concat(width),
30
+ class: 'blockCardView-content-wrap'
31
+ };
32
+ return ['div', attrs, ['a', {
33
+ // To match `packages/linking-platform/smart-card/src/view/CardWithUrl/component-lazy/LoadingCardLink.tsx`
34
+ // Which uses frame styling `packages/linking-platform/smart-card/src/view/InlineCard/Frame/styled.ts`
35
+ style: convertToInlineCss({
36
+ marginLeft: "var(--ds-space-negative-025, -2px)",
37
+ boxDecorationBreak: 'clone',
38
+ WebkitBoxDecorationBreak: 'clone',
39
+ padding: "var(--ds-space-025, 2px)".concat(" 0px"),
40
+ lineHeight: '22px'
41
+ }),
42
+ href: url || ''
43
+ }, (node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.url) || ' ']];
44
+ }
45
+ });
46
+ };