@atlaskit/editor-plugin-card 2.9.2 → 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.
- package/CHANGELOG.md +11 -0
- package/dist/cjs/plugin.js +4 -2
- package/dist/cjs/toDOM-fixes/blockCard.js +53 -0
- package/dist/cjs/toDOM-fixes/embedCard.js +118 -0
- package/dist/es2019/plugin.js +5 -3
- package/dist/es2019/toDOM-fixes/blockCard.js +47 -0
- package/dist/es2019/toDOM-fixes/embedCard.js +111 -0
- package/dist/esm/plugin.js +5 -3
- package/dist/esm/toDOM-fixes/blockCard.js +46 -0
- package/dist/esm/toDOM-fixes/embedCard.js +112 -0
- package/dist/types/toDOM-fixes/blockCard.d.ts +1 -0
- package/dist/types/toDOM-fixes/embedCard.d.ts +1 -0
- package/dist/types-ts4.5/toDOM-fixes/blockCard.d.ts +1 -0
- package/dist/types-ts4.5/toDOM-fixes/embedCard.d.ts +1 -0
- package/package.json +10 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
|
|
3
13
|
## 2.9.2
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -7,6 +17,7 @@
|
|
|
7
17
|
- [#125851](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/125851)
|
|
8
18
|
[`4ffe0a8ea7929`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4ffe0a8ea7929) -
|
|
9
19
|
Refactor node views.
|
|
20
|
+
- Updated dependencies
|
|
10
21
|
|
|
11
22
|
## 2.9.1
|
|
12
23
|
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -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:
|
|
50
|
+
node: (0, _blockCard.blockCardSpecWithFixedToDOM)()
|
|
49
51
|
}];
|
|
50
52
|
if (options.allowEmbeds) {
|
|
51
53
|
nodes.push({
|
|
52
54
|
name: 'embedCard',
|
|
53
|
-
node:
|
|
55
|
+
node: (0, _embedCard.embedCardSpecWithFixedToDOM)()
|
|
54
56
|
});
|
|
55
57
|
}
|
|
56
58
|
return nodes;
|
|
@@ -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
|
+
};
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
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:
|
|
41
|
+
node: blockCardSpecWithFixedToDOM()
|
|
40
42
|
}];
|
|
41
43
|
if (options.allowEmbeds) {
|
|
42
44
|
nodes.push({
|
|
43
45
|
name: 'embedCard',
|
|
44
|
-
node:
|
|
46
|
+
node: embedCardSpecWithFixedToDOM()
|
|
45
47
|
});
|
|
46
48
|
}
|
|
47
49
|
return nodes;
|
|
@@ -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
|
+
};
|
package/dist/esm/plugin.js
CHANGED
|
@@ -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 {
|
|
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:
|
|
43
|
+
node: blockCardSpecWithFixedToDOM()
|
|
42
44
|
}];
|
|
43
45
|
if (options.allowEmbeds) {
|
|
44
46
|
nodes.push({
|
|
45
47
|
name: 'embedCard',
|
|
46
|
-
node:
|
|
48
|
+
node: embedCardSpecWithFixedToDOM()
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
51
|
return nodes;
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* Some of these functions and styling are duplicated from their custom node view equivalents
|
|
6
|
+
*
|
|
7
|
+
* WHY?
|
|
8
|
+
* This will eventually move to `@atlaskit/adf-schema` and we cannot reference
|
|
9
|
+
* `@atlaskit/editor-common` from here or it will cause dependency issues.
|
|
10
|
+
*
|
|
11
|
+
* In the long term likely `toDOM` will move back out of `adf-schema` in which
|
|
12
|
+
* case we can consolidate them.
|
|
13
|
+
*/
|
|
14
|
+
import { embedCard } from '@atlaskit/adf-schema';
|
|
15
|
+
import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
|
|
16
|
+
import { DEFAULT_EMBED_CARD_HEIGHT, DEFAULT_EMBED_CARD_WIDTH } from '@atlaskit/editor-shared-styles';
|
|
17
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
18
|
+
// From `packages/editor/editor-common/src/ui/MediaSingle/styled.tsx`
|
|
19
|
+
function calcMargin(layout) {
|
|
20
|
+
switch (layout) {
|
|
21
|
+
case 'wrap-right':
|
|
22
|
+
return '12px auto 12px 12px';
|
|
23
|
+
case 'wrap-left':
|
|
24
|
+
return '12px 12px 12px auto';
|
|
25
|
+
default:
|
|
26
|
+
return '24px auto';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// From `packages/editor/editor-common/src/ui/MediaSingle/styled.tsx`
|
|
31
|
+
function float(layout) {
|
|
32
|
+
switch (layout) {
|
|
33
|
+
case 'wrap-right':
|
|
34
|
+
return 'right';
|
|
35
|
+
case 'wrap-left':
|
|
36
|
+
return 'left';
|
|
37
|
+
default:
|
|
38
|
+
return 'none';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// From `packages/editor/editor-common/src/media-single/constants.ts`
|
|
43
|
+
var MEDIA_SINGLE_GUTTER_SIZE = 24;
|
|
44
|
+
|
|
45
|
+
// From `packages/editor/editor-common/src/ui/MediaSingle/styled.tsx`
|
|
46
|
+
function calcPxFromPct(pct, lineLength) {
|
|
47
|
+
var maxWidth = lineLength + MEDIA_SINGLE_GUTTER_SIZE;
|
|
48
|
+
return maxWidth * pct - MEDIA_SINGLE_GUTTER_SIZE;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ED-24488: We can't retrieve the editor width from here easily.
|
|
52
|
+
// For now we're using the default line length here, but this will be
|
|
53
|
+
// incorrect on smaller devices.
|
|
54
|
+
var LINE_LENGTH = 760;
|
|
55
|
+
|
|
56
|
+
// @nodeSpecException:toDOM patch
|
|
57
|
+
export var embedCardSpecWithFixedToDOM = function embedCardSpecWithFixedToDOM() {
|
|
58
|
+
if (!fg('platform_editor_lazy-node-views')) {
|
|
59
|
+
return embedCard;
|
|
60
|
+
}
|
|
61
|
+
return _objectSpread(_objectSpread({}, embedCard), {}, {
|
|
62
|
+
toDOM: function toDOM(node) {
|
|
63
|
+
var _node$attrs = node.attrs,
|
|
64
|
+
url = _node$attrs.url,
|
|
65
|
+
layout = _node$attrs.layout,
|
|
66
|
+
width = _node$attrs.width,
|
|
67
|
+
originalWidth = _node$attrs.originalWidth,
|
|
68
|
+
originalHeight = _node$attrs.originalHeight;
|
|
69
|
+
var aspectRatio = originalWidth && originalHeight ? originalWidth / originalHeight : DEFAULT_EMBED_CARD_WIDTH / DEFAULT_EMBED_CARD_HEIGHT;
|
|
70
|
+
var attrs = {
|
|
71
|
+
'data-embed-card': '',
|
|
72
|
+
'data-card-url': url,
|
|
73
|
+
'data-layout': layout,
|
|
74
|
+
'data-width': width,
|
|
75
|
+
'data-original-width': originalWidth,
|
|
76
|
+
'data-original-height': originalHeight,
|
|
77
|
+
class: 'embedCardView-content-wrap',
|
|
78
|
+
// From `packages/editor/editor-plugin-card/src/ui/ResizableEmbedCard.tsx`
|
|
79
|
+
style: convertToInlineCss({
|
|
80
|
+
margin: calcMargin(layout),
|
|
81
|
+
width: "".concat(Math.ceil(calcPxFromPct(width / 100, LINE_LENGTH)), "px"),
|
|
82
|
+
marginRight: layout === 'align-end' ? '0' : '',
|
|
83
|
+
marginLeft: layout === 'align-start' ? '0' : '',
|
|
84
|
+
float: float(layout)
|
|
85
|
+
})
|
|
86
|
+
};
|
|
87
|
+
return ['div', attrs,
|
|
88
|
+
// This is the only modification to the embed card `toDOM`
|
|
89
|
+
// This is to match the behaviour of Card which lazy loads
|
|
90
|
+
// and uses just a URL as a fallback
|
|
91
|
+
//
|
|
92
|
+
// To match: `packages/linking-platform/smart-card/src/view/CardWithUrl/component-lazy/LoadingCardLink.tsx`
|
|
93
|
+
['a', {
|
|
94
|
+
style: convertToInlineCss({
|
|
95
|
+
marginLeft: "var(--ds-space-negative-025, -2px)",
|
|
96
|
+
boxDecorationBreak: 'clone',
|
|
97
|
+
WebkitBoxDecorationBreak: 'clone',
|
|
98
|
+
padding: "var(--ds-space-025, 2px)".concat(" 0px"),
|
|
99
|
+
lineHeight: '22px'
|
|
100
|
+
})
|
|
101
|
+
}, url !== null && url !== void 0 ? url : ''],
|
|
102
|
+
// From `packages/editor/editor-plugin-card/src/ui/ResizableEmbedCard.tsx`
|
|
103
|
+
// The `getHeightDefiningComponent` that defines the height of the element
|
|
104
|
+
['span', {
|
|
105
|
+
style: convertToInlineCss({
|
|
106
|
+
display: 'block',
|
|
107
|
+
paddingBottom: "calc(".concat((1 / aspectRatio * 100).toFixed(3), "% + ", "var(--ds-space-400, 32px)", ")")
|
|
108
|
+
})
|
|
109
|
+
}]];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const blockCardSpecWithFixedToDOM: () => import("prosemirror-model").NodeSpec;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const embedCardSpecWithFixedToDOM: () => import("prosemirror-model").NodeSpec;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const blockCardSpecWithFixedToDOM: () => import("prosemirror-model").NodeSpec;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const embedCardSpecWithFixedToDOM: () => import("prosemirror-model").NodeSpec;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-card",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.3",
|
|
4
4
|
"description": "Card plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@atlaskit/adf-schema": "^40.3.0",
|
|
36
36
|
"@atlaskit/analytics-next": "^9.3.0",
|
|
37
37
|
"@atlaskit/custom-steps": "^0.6.0",
|
|
38
|
-
"@atlaskit/editor-common": "^87.
|
|
38
|
+
"@atlaskit/editor-common": "^87.3.0",
|
|
39
39
|
"@atlaskit/editor-plugin-analytics": "^1.6.0",
|
|
40
40
|
"@atlaskit/editor-plugin-decorations": "^1.2.0",
|
|
41
41
|
"@atlaskit/editor-plugin-editor-disabled": "^1.2.0",
|
|
@@ -47,18 +47,18 @@
|
|
|
47
47
|
"@atlaskit/editor-prosemirror": "5.0.1",
|
|
48
48
|
"@atlaskit/editor-shared-styles": "^2.13.0",
|
|
49
49
|
"@atlaskit/frontend-utilities": "^2.7.0",
|
|
50
|
-
"@atlaskit/icon": "^22.
|
|
50
|
+
"@atlaskit/icon": "^22.10.0",
|
|
51
51
|
"@atlaskit/link-analytics": "^8.3.0",
|
|
52
|
-
"@atlaskit/link-client-extension": "^1.
|
|
52
|
+
"@atlaskit/link-client-extension": "^1.11.0",
|
|
53
53
|
"@atlaskit/link-datasource": "^2.9.0",
|
|
54
54
|
"@atlaskit/linking-common": "^5.8.0",
|
|
55
55
|
"@atlaskit/linking-types": "^8.12.0",
|
|
56
56
|
"@atlaskit/menu": "2.9.0",
|
|
57
57
|
"@atlaskit/platform-feature-flags": "^0.3.0",
|
|
58
58
|
"@atlaskit/primitives": "^11.1.0",
|
|
59
|
-
"@atlaskit/smart-card": "^27.
|
|
59
|
+
"@atlaskit/smart-card": "^27.12.0",
|
|
60
60
|
"@atlaskit/theme": "^12.11.0",
|
|
61
|
-
"@atlaskit/tokens": "^1.
|
|
61
|
+
"@atlaskit/tokens": "^1.57.0",
|
|
62
62
|
"@babel/runtime": "^7.0.0",
|
|
63
63
|
"@emotion/react": "^11.7.1",
|
|
64
64
|
"lodash": "^4.17.21",
|
|
@@ -104,6 +104,10 @@
|
|
|
104
104
|
}
|
|
105
105
|
},
|
|
106
106
|
"platform-feature-flags": {
|
|
107
|
+
"enable_datasource_react_sweet_state": {
|
|
108
|
+
"type": "boolean",
|
|
109
|
+
"referenceOnly": true
|
|
110
|
+
},
|
|
107
111
|
"enable_datasource_nourl_edit_dropdown_datafetch": {
|
|
108
112
|
"type": "boolean"
|
|
109
113
|
},
|