@atlaskit/editor-plugin-card 1.12.1 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/cjs/nodeviews/inlineCard.js +0 -124
- package/dist/cjs/pm-plugins/main.js +2 -3
- package/dist/cjs/toolbar.js +1 -1
- package/dist/cjs/ui/AwarenessWrapper/index.js +29 -11
- package/dist/cjs/ui/NewInlineCardOverlay/index.js +234 -0
- package/dist/es2019/nodeviews/inlineCard.js +1 -112
- package/dist/es2019/pm-plugins/main.js +2 -3
- package/dist/es2019/toolbar.js +1 -1
- package/dist/es2019/ui/AwarenessWrapper/index.js +23 -7
- package/dist/es2019/ui/NewInlineCardOverlay/index.js +213 -0
- package/dist/esm/nodeviews/inlineCard.js +1 -125
- package/dist/esm/pm-plugins/main.js +2 -3
- package/dist/esm/toolbar.js +1 -1
- package/dist/esm/ui/AwarenessWrapper/index.js +29 -11
- package/dist/esm/ui/NewInlineCardOverlay/index.js +224 -0
- package/dist/types/nodeviews/inlineCard.d.ts +1 -18
- package/dist/types/ui/NewInlineCardOverlay/index.d.ts +6 -0
- package/dist/types-ts4.5/nodeviews/inlineCard.d.ts +1 -18
- package/dist/types-ts4.5/ui/NewInlineCardOverlay/index.d.ts +6 -0
- package/package.json +7 -7
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
+
var _excluded = ["children", "isSelected", "isVisible", "testId", "url"];
|
|
6
|
+
/* eslint-disable @atlaskit/design-system/no-nested-styles */
|
|
7
|
+
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
8
|
+
/** @jsx jsx */
|
|
9
|
+
import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
10
|
+
import { css, jsx } from '@emotion/react';
|
|
11
|
+
import debounce from 'lodash/debounce';
|
|
12
|
+
import { useIntl } from 'react-intl-next';
|
|
13
|
+
import { cardMessages as messages } from '@atlaskit/editor-common/messages';
|
|
14
|
+
import { ZERO_WIDTH_JOINER } from '@atlaskit/editor-common/utils';
|
|
15
|
+
import PreferencesIcon from '@atlaskit/icon/glyph/preferences';
|
|
16
|
+
import { B100, N0, N700 } from '@atlaskit/theme/colors';
|
|
17
|
+
import { getChildElement, getIconSize, getInlineCardAvailableWidth, getOverlayWidths, isOneLine } from '../InlineCardOverlay/utils';
|
|
18
|
+
var DEBOUNCE_IN_MS = 5;
|
|
19
|
+
var ESTIMATED_MIN_WIDTH_IN_PX = 16;
|
|
20
|
+
var PADDING_IN_PX = 4;
|
|
21
|
+
var ICON_WIDTH_IN_PX = 14;
|
|
22
|
+
var ICON_AND_LABEL_CLASSNAME = 'ak-editor-card-overlay-icon-and-label';
|
|
23
|
+
var OVERLAY_LABEL_CLASSNAME = 'ak-editor-card-overlay-label';
|
|
24
|
+
var OVERLAY_MARKER_CLASSNAME = 'ak-editor-card-overlay-marker';
|
|
25
|
+
var TEXT_NODE_SELECTOR = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'].join(',');
|
|
26
|
+
var SMART_LINK_BACKGROUND_COLOR = "var(--ds-surface-raised, ".concat(N0, ")");
|
|
27
|
+
// TODO: This should be lighter to match the rest of the button
|
|
28
|
+
var SMART_LINK_ACTIVE_COLOR = "var(--ds-background-selected, ".concat(B100, ")");
|
|
29
|
+
var containerStyles = css({
|
|
30
|
+
position: 'relative',
|
|
31
|
+
lineHeight: 'normal',
|
|
32
|
+
':active': _defineProperty({}, ".".concat(ICON_AND_LABEL_CLASSNAME), {
|
|
33
|
+
background: SMART_LINK_ACTIVE_COLOR
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
var overlayStyles = css({
|
|
37
|
+
// Set default styling to be invisible but available in dom for width calculation.
|
|
38
|
+
visibility: 'hidden',
|
|
39
|
+
marginTop: "var(--ds-space-050, 4px)",
|
|
40
|
+
position: 'absolute',
|
|
41
|
+
verticalAlign: 'text-top',
|
|
42
|
+
height: '1lh',
|
|
43
|
+
'@supports not (height: 1lh)': {
|
|
44
|
+
height: '1.2em'
|
|
45
|
+
},
|
|
46
|
+
overflow: 'hidden',
|
|
47
|
+
// EDM-1717: box-shadow Safari fix bring load wrapper zIndex to 1
|
|
48
|
+
zIndex: 2,
|
|
49
|
+
pointerEvents: 'none'
|
|
50
|
+
});
|
|
51
|
+
var showOverlayStyles = css({
|
|
52
|
+
visibility: 'visible'
|
|
53
|
+
});
|
|
54
|
+
var iconStyles = css({
|
|
55
|
+
// Position icon in the middle
|
|
56
|
+
span: {
|
|
57
|
+
display: 'flex'
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
var labelStyles = css({
|
|
61
|
+
fontSize: '0.875em',
|
|
62
|
+
fontWeight: '600',
|
|
63
|
+
width: 'max-content'
|
|
64
|
+
});
|
|
65
|
+
var iconAndLabelStyles = css({
|
|
66
|
+
display: 'flex',
|
|
67
|
+
alignItems: 'center',
|
|
68
|
+
height: '100%',
|
|
69
|
+
marginLeft: "var(--ds-space-050, 4px)",
|
|
70
|
+
marginRight: "var(--ds-space-025, 2px)",
|
|
71
|
+
background: SMART_LINK_BACKGROUND_COLOR,
|
|
72
|
+
color: "var(--ds-text-subtlest, ".concat(N700, ")")
|
|
73
|
+
});
|
|
74
|
+
var overflowingContainerStyles = css({
|
|
75
|
+
display: 'flex',
|
|
76
|
+
flexDirection: 'row-reverse',
|
|
77
|
+
alignItems: 'center',
|
|
78
|
+
width: 'max-content',
|
|
79
|
+
height: '100%'
|
|
80
|
+
});
|
|
81
|
+
var NarrowInlineCardOverlay = function NarrowInlineCardOverlay(_ref) {
|
|
82
|
+
var children = _ref.children,
|
|
83
|
+
_ref$isSelected = _ref.isSelected,
|
|
84
|
+
isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected,
|
|
85
|
+
_ref$isVisible = _ref.isVisible,
|
|
86
|
+
isVisible = _ref$isVisible === void 0 ? false : _ref$isVisible,
|
|
87
|
+
_ref$testId = _ref.testId,
|
|
88
|
+
testId = _ref$testId === void 0 ? 'inline-card-overlay' : _ref$testId,
|
|
89
|
+
url = _ref.url,
|
|
90
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
91
|
+
var _useState = useState(false),
|
|
92
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
93
|
+
showOverlay = _useState2[0],
|
|
94
|
+
setShowOverlay = _useState2[1];
|
|
95
|
+
var _useState3 = useState(undefined),
|
|
96
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
97
|
+
availableWidth = _useState4[0],
|
|
98
|
+
setAvailableWidth = _useState4[1];
|
|
99
|
+
var maxOverlayWidth = useRef(0);
|
|
100
|
+
var minOverlayWidth = useRef(ESTIMATED_MIN_WIDTH_IN_PX);
|
|
101
|
+
var parentWidth = useRef(0);
|
|
102
|
+
var iconSize = useRef('small');
|
|
103
|
+
var containerRef = useRef(null);
|
|
104
|
+
|
|
105
|
+
// TODO EDM-9843: Use availableWidth for small link edge case
|
|
106
|
+
availableWidth;
|
|
107
|
+
var setVisibility = useCallback(function () {
|
|
108
|
+
if (!containerRef.current || !maxOverlayWidth.current) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
var marker = getChildElement(containerRef, ".".concat(OVERLAY_MARKER_CLASSNAME));
|
|
112
|
+
if (!marker) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
var oneLine = isOneLine(containerRef.current, marker);
|
|
117
|
+
|
|
118
|
+
// Get the width of the available space to display overlay.
|
|
119
|
+
// This is the width of the inline link itself. If the inline
|
|
120
|
+
// is wrapped to the next line, this is width of the last line.
|
|
121
|
+
var _availableWidth = getInlineCardAvailableWidth(containerRef.current, marker) - PADDING_IN_PX - (
|
|
122
|
+
// Always leave at least the icon visible
|
|
123
|
+
oneLine ? ICON_WIDTH_IN_PX + PADDING_IN_PX : 0);
|
|
124
|
+
setAvailableWidth(_availableWidth);
|
|
125
|
+
var canShowOverlay = !isSelected;
|
|
126
|
+
setShowOverlay(canShowOverlay);
|
|
127
|
+
} catch (_unused) {
|
|
128
|
+
// If something goes wrong, hide the overlay all together.
|
|
129
|
+
setShowOverlay(false);
|
|
130
|
+
}
|
|
131
|
+
}, [isSelected]);
|
|
132
|
+
useLayoutEffect(function () {
|
|
133
|
+
// Using useLayoutEffect here.
|
|
134
|
+
// 1) We want all to be able to determine whether to display label before
|
|
135
|
+
// the overlay becomes visible.
|
|
136
|
+
// 2) We need to wait for the refs to be assigned to be able to do determine
|
|
137
|
+
// the width of the overlay.
|
|
138
|
+
if (!containerRef.current) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// This should run only once
|
|
143
|
+
if (!maxOverlayWidth.current) {
|
|
144
|
+
var iconAndLabel = getChildElement(containerRef, ".".concat(ICON_AND_LABEL_CLASSNAME));
|
|
145
|
+
var _label = getChildElement(containerRef, ".".concat(OVERLAY_LABEL_CLASSNAME));
|
|
146
|
+
if (iconAndLabel && _label) {
|
|
147
|
+
// Set overlay max (label + icon) and min (icon only) width.
|
|
148
|
+
var _getOverlayWidths = getOverlayWidths(iconAndLabel, _label),
|
|
149
|
+
max = _getOverlayWidths.max,
|
|
150
|
+
min = _getOverlayWidths.min;
|
|
151
|
+
maxOverlayWidth.current = max;
|
|
152
|
+
minOverlayWidth.current = min;
|
|
153
|
+
iconSize.current = getIconSize(_label);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (isVisible) {
|
|
157
|
+
setVisibility();
|
|
158
|
+
}
|
|
159
|
+
}, [setVisibility, isVisible]);
|
|
160
|
+
useEffect(function () {
|
|
161
|
+
var _containerRef$current;
|
|
162
|
+
// Find the closest block parent to observe size change
|
|
163
|
+
var parent = containerRef === null || containerRef === void 0 || (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.closest(TEXT_NODE_SELECTOR);
|
|
164
|
+
if (!parent) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
var updateOverlay = debounce(function (entries) {
|
|
168
|
+
var _entries$;
|
|
169
|
+
if (!isVisible) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
var size = entries === null || entries === void 0 || (_entries$ = entries[0]) === null || _entries$ === void 0 || (_entries$ = _entries$.contentBoxSize) === null || _entries$ === void 0 || (_entries$ = _entries$[0]) === null || _entries$ === void 0 ? void 0 : _entries$.inlineSize;
|
|
173
|
+
if (!size) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (!parentWidth.current) {
|
|
177
|
+
parentWidth.current = size;
|
|
178
|
+
}
|
|
179
|
+
if (parentWidth.current === size) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
parentWidth.current = size;
|
|
183
|
+
setVisibility();
|
|
184
|
+
}, DEBOUNCE_IN_MS);
|
|
185
|
+
var observer = new ResizeObserver(updateOverlay);
|
|
186
|
+
observer.observe(parent);
|
|
187
|
+
return function () {
|
|
188
|
+
observer.disconnect();
|
|
189
|
+
};
|
|
190
|
+
}, [isVisible, setVisibility]);
|
|
191
|
+
var intl = useIntl();
|
|
192
|
+
var label = intl.formatMessage(messages.inlineOverlay);
|
|
193
|
+
return jsx("span", _extends({}, props, {
|
|
194
|
+
css: containerStyles,
|
|
195
|
+
ref: containerRef
|
|
196
|
+
}), isVisible && jsx(React.Fragment, null, jsx("span", {
|
|
197
|
+
"aria-hidden": "true",
|
|
198
|
+
className: OVERLAY_MARKER_CLASSNAME
|
|
199
|
+
}, ZERO_WIDTH_JOINER), jsx("a", {
|
|
200
|
+
css: [overlayStyles, showOverlay && showOverlayStyles],
|
|
201
|
+
"data-testid": testId,
|
|
202
|
+
href: url,
|
|
203
|
+
onClick: function onClick(e) {
|
|
204
|
+
return e.preventDefault();
|
|
205
|
+
},
|
|
206
|
+
tabIndex: -1
|
|
207
|
+
}, jsx("span", {
|
|
208
|
+
css: overflowingContainerStyles
|
|
209
|
+
}, jsx("span", {
|
|
210
|
+
css: iconAndLabelStyles,
|
|
211
|
+
className: ICON_AND_LABEL_CLASSNAME
|
|
212
|
+
}, jsx("span", {
|
|
213
|
+
css: iconStyles
|
|
214
|
+
}, jsx(PreferencesIcon, {
|
|
215
|
+
label: label,
|
|
216
|
+
size: iconSize.current,
|
|
217
|
+
testId: "".concat(testId, "-icon")
|
|
218
|
+
})), jsx("span", {
|
|
219
|
+
css: labelStyles,
|
|
220
|
+
className: OVERLAY_LABEL_CLASSNAME,
|
|
221
|
+
"data-testid": "".concat(testId, "-label")
|
|
222
|
+
}))))), children);
|
|
223
|
+
};
|
|
224
|
+
export default NarrowInlineCardOverlay;
|
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
1
|
+
/// <reference types="react" />
|
|
3
2
|
import type { InlineNodeViewComponentProps } from '@atlaskit/editor-common/react-node-view';
|
|
4
3
|
import type { SmartCardProps } from './genericCard';
|
|
5
|
-
export declare class InlineCardComponent extends React.PureComponent<SmartCardProps> {
|
|
6
|
-
private scrollContainer?;
|
|
7
|
-
static contextTypes: {
|
|
8
|
-
contextAdapter: PropTypes.Requireable<object>;
|
|
9
|
-
};
|
|
10
|
-
UNSAFE_componentWillMount(): void;
|
|
11
|
-
onResolve: (data: {
|
|
12
|
-
url?: string | undefined;
|
|
13
|
-
title?: string | undefined;
|
|
14
|
-
}) => void;
|
|
15
|
-
onError: (data: {
|
|
16
|
-
url?: string | undefined;
|
|
17
|
-
err?: Error | undefined;
|
|
18
|
-
}) => void;
|
|
19
|
-
render(): JSX.Element | null;
|
|
20
|
-
}
|
|
21
4
|
export type InlineCardNodeViewProps = Pick<SmartCardProps, 'useAlternativePreloader' | 'actionOptions' | 'showServerActions' | 'allowEmbeds' | 'allowBlockCards' | 'enableInlineUpgradeFeatures' | 'pluginInjectionApi' | 'onClickCallback'>;
|
|
22
5
|
type InlineCardWithAwarenessProps = {
|
|
23
6
|
allowEmbeds?: boolean;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { jsx } from '@emotion/react';
|
|
4
|
+
import type { InlineCardOverlayProps } from '../InlineCardOverlay/types';
|
|
5
|
+
declare const NarrowInlineCardOverlay: ({ children, isSelected, isVisible, testId, url, ...props }: React.PropsWithChildren<InlineCardOverlayProps>) => jsx.JSX.Element;
|
|
6
|
+
export default NarrowInlineCardOverlay;
|
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
1
|
+
/// <reference types="react" />
|
|
3
2
|
import type { InlineNodeViewComponentProps } from '@atlaskit/editor-common/react-node-view';
|
|
4
3
|
import type { SmartCardProps } from './genericCard';
|
|
5
|
-
export declare class InlineCardComponent extends React.PureComponent<SmartCardProps> {
|
|
6
|
-
private scrollContainer?;
|
|
7
|
-
static contextTypes: {
|
|
8
|
-
contextAdapter: PropTypes.Requireable<object>;
|
|
9
|
-
};
|
|
10
|
-
UNSAFE_componentWillMount(): void;
|
|
11
|
-
onResolve: (data: {
|
|
12
|
-
url?: string | undefined;
|
|
13
|
-
title?: string | undefined;
|
|
14
|
-
}) => void;
|
|
15
|
-
onError: (data: {
|
|
16
|
-
url?: string | undefined;
|
|
17
|
-
err?: Error | undefined;
|
|
18
|
-
}) => void;
|
|
19
|
-
render(): JSX.Element | null;
|
|
20
|
-
}
|
|
21
4
|
export type InlineCardNodeViewProps = Pick<SmartCardProps, 'useAlternativePreloader' | 'actionOptions' | 'showServerActions' | 'allowEmbeds' | 'allowBlockCards' | 'enableInlineUpgradeFeatures' | 'pluginInjectionApi' | 'onClickCallback'>;
|
|
22
5
|
type InlineCardWithAwarenessProps = {
|
|
23
6
|
allowEmbeds?: boolean;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { jsx } from '@emotion/react';
|
|
4
|
+
import type { InlineCardOverlayProps } from '../InlineCardOverlay/types';
|
|
5
|
+
declare const NarrowInlineCardOverlay: ({ children, isSelected, isVisible, testId, url, ...props }: React.PropsWithChildren<InlineCardOverlayProps>) => jsx.JSX.Element;
|
|
6
|
+
export default NarrowInlineCardOverlay;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-card",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "Card plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
".": "./src/index.ts"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@atlaskit/adf-schema": "^36.
|
|
35
|
+
"@atlaskit/adf-schema": "^36.8.0",
|
|
36
36
|
"@atlaskit/analytics-next": "^9.3.0",
|
|
37
37
|
"@atlaskit/custom-steps": "^0.2.0",
|
|
38
|
-
"@atlaskit/editor-common": "^80.
|
|
38
|
+
"@atlaskit/editor-common": "^80.4.0",
|
|
39
39
|
"@atlaskit/editor-plugin-analytics": "^1.2.0",
|
|
40
40
|
"@atlaskit/editor-plugin-decorations": "^1.1.0",
|
|
41
41
|
"@atlaskit/editor-plugin-editor-viewmode": "^1.1.0",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"@atlaskit/icon": "^22.2.0",
|
|
51
51
|
"@atlaskit/link-analytics": "^8.3.0",
|
|
52
52
|
"@atlaskit/link-client-extension": "^1.8.0",
|
|
53
|
-
"@atlaskit/link-datasource": "^2.
|
|
53
|
+
"@atlaskit/link-datasource": "^2.3.0",
|
|
54
54
|
"@atlaskit/linking-common": "^5.6.0",
|
|
55
55
|
"@atlaskit/linking-types": "^8.8.0",
|
|
56
56
|
"@atlaskit/platform-feature-flags": "^0.2.0",
|
|
57
|
-
"@atlaskit/primitives": "^6.
|
|
58
|
-
"@atlaskit/smart-card": "^26.
|
|
57
|
+
"@atlaskit/primitives": "^6.2.0",
|
|
58
|
+
"@atlaskit/smart-card": "^26.69.0",
|
|
59
59
|
"@atlaskit/theme": "^12.8.0",
|
|
60
60
|
"@atlaskit/tokens": "^1.48.0",
|
|
61
61
|
"@babel/runtime": "^7.0.0",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
},
|
|
106
106
|
"prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.0",
|
|
107
107
|
"platform-feature-flags": {
|
|
108
|
-
"platform.linking-platform.smart-
|
|
108
|
+
"platform.linking-platform.smart-links-in-live-pages": {
|
|
109
109
|
"type": "boolean"
|
|
110
110
|
},
|
|
111
111
|
"platform.linking-platform.datasource-word_wrap": {
|