@atlaskit/editor-plugin-card 0.13.4 → 0.13.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/editor-plugin-card
2
2
 
3
+ ## 0.13.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#43035](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43035) [`705854f13b3`](https://bitbucket.org/atlassian/atlassian-frontend/commits/705854f13b3) - [ux] Show inline card overlay on selected (behind feature flag)
8
+ - [#43417](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43417) [`3f3c17f0273`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3f3c17f0273) - ED-20971 Upgrade adf-schema package to ^34.0.0
9
+ - [#43496](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43496) [`290e75ca7f2`](https://bitbucket.org/atlassian/atlassian-frontend/commits/290e75ca7f2) - Fixes uncaught error when using arrow keys to move selection into inline card.
10
+ - Updated dependencies
11
+
12
+ ## 0.13.5
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+
3
18
  ## 0.13.4
4
19
 
5
20
  ### Patch Changes
@@ -140,6 +140,8 @@ function InlineCardNodeView(props) {
140
140
  useAlternativePreloader: useAlternativePreloader
141
141
  });
142
142
  }
143
+
144
+ // BEGIN: Awareness (To be revisited in EDM-8508)
143
145
  var editorState = view.state;
144
146
  var linkPosition = getPos && typeof getPos() === 'number' ? getPos() : undefined;
145
147
  var canBeUpgradedToEmbed = !!linkPosition && allowEmbeds ? (0, _utils.isEmbedSupportedAtPosition)(linkPosition, editorState, 'inline') : false;
@@ -147,6 +149,8 @@ function InlineCardNodeView(props) {
147
149
  var isPulseEnabled = enableInlineUpgradeFeatures && canBeUpgradedToEmbed;
148
150
  var isOverlayEnabled = enableInlineUpgradeFeatures && (canBeUpgradedToEmbed || canBeUpgradedToBlock);
149
151
  var isSelected = view.state.selection instanceof _state.NodeSelection && ((_view$state$selection = view.state.selection) === null || _view$state$selection === void 0 || (_view$state$selection = _view$state$selection.node) === null || _view$state$selection === void 0 ? void 0 : _view$state$selection.type) === view.state.schema.nodes.inlineCard && ((_view$state$selection2 = view.state.selection) === null || _view$state$selection2 === void 0 ? void 0 : _view$state$selection2.from) === getPos();
152
+ // END: Awareness
153
+
150
154
  return /*#__PURE__*/_react.default.createElement(WrappedInlineCardWithAwareness, {
151
155
  node: node,
152
156
  view: view,
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.InlineCardWithAwareness = void 0;
8
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
9
  var _react = require("react");
11
10
  var _react2 = require("@emotion/react");
@@ -37,17 +36,17 @@ var InlineCard = function InlineCard(_ref) {
37
36
  isOverlayEnabled = _ref.isOverlayEnabled,
38
37
  isPulseEnabled = _ref.isPulseEnabled,
39
38
  pluginInjectionApi = _ref.pluginInjectionApi,
40
- isSelected = _ref.isSelected;
39
+ _ref$isSelected = _ref.isSelected,
40
+ isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected;
41
41
  var _node$attrs = node.attrs,
42
42
  url = _node$attrs.url,
43
43
  data = _node$attrs.data;
44
44
 
45
- // A complete show/hide logic for the overlay will be implemented
46
- // in EDM-8239 and EDM-8241
45
+ // BEGIN: Awareness (To be revisited in EDM-8508)
47
46
  var _useState = (0, _react.useState)(false),
48
47
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
49
- isOverlayVisible = _useState2[0],
50
- setIsOverlayVisible = _useState2[1];
48
+ isHovered = _useState2[0],
49
+ setIsHovered = _useState2[1];
51
50
  var linkPosition = (0, _react.useMemo)(function () {
52
51
  if (!getPos || typeof getPos === 'boolean') {
53
52
  return undefined;
@@ -72,6 +71,8 @@ var InlineCard = function InlineCard(_ref) {
72
71
  if (isSelected && shouldShowToolbarPulse && !(0, _localStorage.isLocalStorageKeyDiscovered)(_localStorage.LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR)) {
73
72
  (0, _localStorage.markLocalStorageKeyDiscovered)(_localStorage.LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK);
74
73
  }
74
+ // END: Awareness
75
+
75
76
  var scrollContainer = (0, _react.useMemo)(function () {
76
77
  return (0, _ui.findOverflowScrollParent)(view.dom) || undefined;
77
78
  }, [view.dom]);
@@ -107,10 +108,7 @@ var InlineCard = function InlineCard(_ref) {
107
108
  });
108
109
  }, [onResolve]);
109
110
  var innerCard = (0, _react.useMemo)(function () {
110
- return (0, _react2.jsx)(_InlineCardOverlay.default, {
111
- isVisible: isOverlayVisible,
112
- url: url
113
- }, (0, _react2.jsx)(_smartCard.Card, {
111
+ return (0, _react2.jsx)(_smartCard.Card, {
114
112
  key: url,
115
113
  url: url,
116
114
  data: data,
@@ -121,25 +119,34 @@ var InlineCard = function InlineCard(_ref) {
121
119
  onError: onError,
122
120
  inlinePreloaderStyle: useAlternativePreloader ? 'on-right-without-skeleton' : undefined,
123
121
  showServerActions: showServerActions
124
- }));
125
- }, [data, isOverlayVisible, onError, onResolve, scrollContainer, showServerActions, url, useAlternativePreloader]);
126
- var card = (0, _react.useMemo)(function () {
127
- return (0, _react2.jsx)("span", (0, _extends2.default)({
128
- css: shouldShowLinkPulse && loaderWrapperStyles,
129
- className: "card"
130
- }, shouldShowLinkOverlay ? {
122
+ });
123
+ }, [data, onError, onResolve, scrollContainer, showServerActions, url, useAlternativePreloader]);
124
+
125
+ // BEGIN: Awareness (To be revisited in EDM-8508)
126
+ var cardWithOverlay = (0, _react.useMemo)(function () {
127
+ return shouldShowLinkOverlay ? (0, _react2.jsx)(_InlineCardOverlay.default, {
128
+ isSelected: isSelected,
129
+ isVisible: isHovered || isSelected,
131
130
  onMouseEnter: function onMouseEnter() {
132
- return setIsOverlayVisible(true);
131
+ return setIsHovered(true);
133
132
  },
134
133
  onMouseLeave: function onMouseLeave() {
135
- return setIsOverlayVisible(false);
136
- }
137
- } : {}), shouldShowLinkPulse ? (0, _react2.jsx)(_pulse.DiscoveryPulse, {
134
+ return setIsHovered(false);
135
+ },
136
+ url: url
137
+ }, innerCard) : innerCard;
138
+ }, [innerCard, isHovered, isSelected, shouldShowLinkOverlay, url]);
139
+ var card = (0, _react.useMemo)(function () {
140
+ return (0, _react2.jsx)("span", {
141
+ css: shouldShowLinkPulse && loaderWrapperStyles,
142
+ className: "card"
143
+ }, shouldShowLinkPulse ? (0, _react2.jsx)(_pulse.DiscoveryPulse, {
138
144
  localStorageKey: _localStorage.LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK,
139
145
  localStorageKeyExpirationInMs: _localStorage.ONE_DAY_IN_MILLISECONDS,
140
- discoveryMode: 'start'
141
- }, innerCard) : innerCard);
142
- }, [shouldShowLinkPulse, shouldShowLinkOverlay, innerCard]);
146
+ discoveryMode: "start"
147
+ }, cardWithOverlay) : cardWithOverlay);
148
+ }, [shouldShowLinkPulse, cardWithOverlay]);
149
+ // END: Awareness
143
150
 
144
151
  // [WS-2307]: we only render card wrapped into a Provider when the value is ready,
145
152
  // otherwise if we got data, we can render the card directly since it doesn't need the Provider
@@ -26,7 +26,7 @@ var getClosestInlineCardPos = function getClosestInlineCardPos(state, editorView
26
26
  left: coord.left,
27
27
  top: direction === 'up' ? coord.top - lookupPixel : coord.bottom + lookupPixel
28
28
  })) === null || _editorView$posAtCoor === void 0 ? void 0 : _editorView$posAtCoor.inside;
29
- if (nearPos) {
29
+ if (typeof nearPos === 'number' && nearPos > -1) {
30
30
  var newNode = state.doc.nodeAt(nearPos);
31
31
  if (newNode) {
32
32
  if (newNode.type !== inlineCardType || (0, _utils2.findChildren)(parent, function (node) {
@@ -6,21 +6,32 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.default = void 0;
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
13
  var _react = _interopRequireWildcard(require("react"));
12
14
  var _react2 = require("@emotion/react");
15
+ var _debounce = _interopRequireDefault(require("lodash/debounce"));
13
16
  var _reactIntlNext = require("react-intl-next");
14
17
  var _utils = require("@atlaskit/editor-common/utils");
15
18
  var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/hipchat/chevron-down"));
16
19
  var _chevronUp = _interopRequireDefault(require("@atlaskit/icon/glyph/hipchat/chevron-up"));
17
20
  var _colors = require("@atlaskit/theme/colors");
18
21
  var _messages = require("../../messages");
22
+ var _utils2 = require("./utils");
23
+ var _excluded = ["children", "isSelected", "isVisible", "testId", "url"];
19
24
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
20
25
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
26
  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; }
22
27
  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; } /** @jsx jsx */
28
+ var DEBOUNCE_IN_MS = 5;
29
+ var ESTIMATED_MIN_WIDTH_IN_PX = 16;
23
30
  var PADDING_IN_PX = 2;
31
+ var OVERLAY_CLASSNAME = 'ak-editor-card-overlay';
32
+ var OVERLAY_LABEL_CLASSNAME = 'ak-editor-card-overlay-label';
33
+ var OVERLAY_MARKER_CLASSNAME = 'ak-editor-card-overlay-marker';
34
+ var TEXT_NODE_SELECTOR = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'].join(',');
24
35
  var containerStyles = (0, _react2.css)({
25
36
  position: 'relative',
26
37
  lineHeight: 'normal'
@@ -30,9 +41,10 @@ var linkStyles = (0, _react2.css)({
30
41
  textDecoration: 'none'
31
42
  });
32
43
  var overlayStyles = (0, _react2.css)({
44
+ // Visibility is set directly on element via style prop
45
+ display: 'inline-flex',
33
46
  // Positioning
34
47
  position: 'relative',
35
- display: 'inline-flex',
36
48
  flexWrap: 'nowrap',
37
49
  alignItems: 'center',
38
50
  alignSelf: 'stretch',
@@ -98,75 +110,136 @@ var markerStyles = (0, _react2.css)({
98
110
  });
99
111
  var InlineCardOverlay = function InlineCardOverlay(_ref) {
100
112
  var children = _ref.children,
101
- _ref$isToolbarOpen = _ref.isToolbarOpen,
102
- isToolbarOpen = _ref$isToolbarOpen === void 0 ? false : _ref$isToolbarOpen,
113
+ _ref$isSelected = _ref.isSelected,
114
+ isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected,
103
115
  _ref$isVisible = _ref.isVisible,
104
116
  isVisible = _ref$isVisible === void 0 ? false : _ref$isVisible,
105
117
  _ref$testId = _ref.testId,
106
118
  testId = _ref$testId === void 0 ? 'inline-card-overlay' : _ref$testId,
107
- url = _ref.url;
119
+ url = _ref.url,
120
+ props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
108
121
  var _useState = (0, _react.useState)(true),
109
122
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
110
- showLabel = _useState2[0],
111
- setShowLabel = _useState2[1];
112
- var _useState3 = (0, _react.useState)(0),
123
+ showOverlay = _useState2[0],
124
+ setShowOverlay = _useState2[1];
125
+ var _useState3 = (0, _react.useState)(true),
113
126
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
114
- overlayWidth = _useState4[0],
115
- setOverlayWidth = _useState4[1];
127
+ showLabel = _useState4[0],
128
+ setShowLabel = _useState4[1];
129
+ var _useState5 = (0, _react.useState)(0),
130
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
131
+ overlayWidth = _useState6[0],
132
+ setOverlayWidth = _useState6[1];
133
+ var maxOverlayWidth = (0, _react.useRef)(0);
134
+ var minOverlayWidth = (0, _react.useRef)(ESTIMATED_MIN_WIDTH_IN_PX);
135
+ var parentWidth = (0, _react.useRef)(0);
116
136
  var containerRef = (0, _react.useRef)(null);
117
- var markerRef = (0, _react.useRef)(null);
118
- var overlayRef = (0, _react.useRef)(null);
119
- var labelRef = (0, _react.useRef)(null);
120
- (0, _react.useLayoutEffect)(function () {
121
- if (!isVisible) {
122
- // Reset to default state for width calculation when the component become visible.
123
- setShowLabel(true);
137
+ var setVisibility = (0, _react.useCallback)(function () {
138
+ if (!containerRef.current || !maxOverlayWidth.current) {
139
+ return;
140
+ }
141
+ var marker = (0, _utils2.getChildElement)(containerRef, ".".concat(OVERLAY_MARKER_CLASSNAME));
142
+ if (!marker) {
124
143
  return;
125
144
  }
126
145
  try {
127
- var _containerRef$current, _containerRef$current2, _markerRef$current$ge, _markerRef$current, _overlayRef$current$g, _overlayRef$current, _labelRef$current$get, _labelRef$current;
128
- // Get the width of the available space to display overlay
129
- var start = (_containerRef$current = containerRef === null || containerRef === void 0 || (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 || (_containerRef$current2 = _containerRef$current2.getBoundingClientRect()) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.left) !== null && _containerRef$current !== void 0 ? _containerRef$current : 0;
130
- var end = (_markerRef$current$ge = markerRef === null || markerRef === void 0 || (_markerRef$current = markerRef.current) === null || _markerRef$current === void 0 || (_markerRef$current = _markerRef$current.getBoundingClientRect()) === null || _markerRef$current === void 0 ? void 0 : _markerRef$current.left) !== null && _markerRef$current$ge !== void 0 ? _markerRef$current$ge : 0;
131
- var availableWidth = end - start - PADDING_IN_PX;
132
-
133
- // Get overlay width and label width
134
- var _overlayWidth = (_overlayRef$current$g = overlayRef === null || overlayRef === void 0 || (_overlayRef$current = overlayRef.current) === null || _overlayRef$current === void 0 || (_overlayRef$current = _overlayRef$current.getBoundingClientRect()) === null || _overlayRef$current === void 0 ? void 0 : _overlayRef$current.width) !== null && _overlayRef$current$g !== void 0 ? _overlayRef$current$g : 0;
146
+ // Get the width of the available space to display overlay.
147
+ // This is the width of the inline link itself. If the inline
148
+ // is wrapped to the next line, this is width of the last line.
149
+ var availableWidth = (0, _utils2.getInlineCardAvailableWidth)(containerRef.current, marker) - PADDING_IN_PX;
135
150
 
136
- // Show label if there is enough space to display
137
- var shouldShowLabel = availableWidth > 0 && _overlayWidth > 0 ? availableWidth > _overlayWidth : false;
138
- setShowLabel(shouldShowLabel);
151
+ // If available width is less than the min width of overlay, don't show overlay.
152
+ var canShowOverlay = availableWidth > minOverlayWidth.current;
153
+ setShowOverlay(canShowOverlay);
154
+ if (!canShowOverlay) {
155
+ return;
156
+ }
139
157
 
140
- // We use relative positioning and need to set
141
- // negative margin left (ltr) as the width of the overlay
142
- // to make the overlay position on top of inline link.
143
- var labelWidth = (_labelRef$current$get = labelRef === null || labelRef === void 0 || (_labelRef$current = labelRef.current) === null || _labelRef$current === void 0 || (_labelRef$current = _labelRef$current.getBoundingClientRect()) === null || _labelRef$current === void 0 ? void 0 : _labelRef$current.width) !== null && _labelRef$current$get !== void 0 ? _labelRef$current$get : 0;
144
- var newOverlayWidth = shouldShowLabel ? _overlayWidth : _overlayWidth - labelWidth;
145
- setOverlayWidth(newOverlayWidth);
158
+ // Otherwise, check if overlay can be show in full context with label and icon.
159
+ var canShowLabel = availableWidth > maxOverlayWidth.current + PADDING_IN_PX;
160
+ setShowLabel(canShowLabel);
161
+ setOverlayWidth(canShowLabel ? maxOverlayWidth.current : minOverlayWidth.current);
146
162
  } catch (_unused) {
147
- // If something goes wrong, play it safe by hiding label so that
148
- // the component does not look too janky.
149
- setShowLabel(false);
163
+ // If something goes wrong, hide the overlay all together.
164
+ setShowOverlay(false);
165
+ }
166
+ }, []);
167
+ (0, _react.useLayoutEffect)(function () {
168
+ // Using useLayoutEffect here.
169
+ // 1) We want all to be able to determine whether to display label before
170
+ // the overlay becomes visible.
171
+ // 2) We need to wait for the refs to be assigned to be able to do determine
172
+ // the width of the overlay.
173
+ if (!containerRef.current) {
174
+ return;
175
+ }
176
+ if (!maxOverlayWidth.current) {
177
+ var overlay = (0, _utils2.getChildElement)(containerRef, ".".concat(OVERLAY_CLASSNAME));
178
+ var _label = (0, _utils2.getChildElement)(containerRef, ".".concat(OVERLAY_LABEL_CLASSNAME));
179
+ if (overlay && _label) {
180
+ // Set overlay max (label + icon) and min (icon only) width.
181
+ // This should run only once.
182
+ var _getOverlayWidths = (0, _utils2.getOverlayWidths)(overlay, _label),
183
+ max = _getOverlayWidths.max,
184
+ min = _getOverlayWidths.min;
185
+ maxOverlayWidth.current = max;
186
+ minOverlayWidth.current = min;
187
+ }
188
+ }
189
+ if (isVisible) {
190
+ setVisibility();
191
+ }
192
+ }, [setVisibility, isVisible]);
193
+ (0, _react.useEffect)(function () {
194
+ var _containerRef$current;
195
+ // Find the closest block parent to observe size change
196
+ var parent = containerRef === null || containerRef === void 0 || (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.closest(TEXT_NODE_SELECTOR);
197
+ if (!parent) {
198
+ return;
150
199
  }
151
- }, [isVisible]);
200
+ var updateOverlay = (0, _debounce.default)(function (entries) {
201
+ var _entries$;
202
+ if (!isVisible) {
203
+ return;
204
+ }
205
+ 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;
206
+ if (!size) {
207
+ return;
208
+ }
209
+ if (!parentWidth.current) {
210
+ parentWidth.current = size;
211
+ }
212
+ if (parentWidth.current === size) {
213
+ return;
214
+ }
215
+ parentWidth.current = size;
216
+ setVisibility();
217
+ }, DEBOUNCE_IN_MS);
218
+ var observer = new ResizeObserver(updateOverlay);
219
+ observer.observe(parent);
220
+ return function () {
221
+ observer.disconnect();
222
+ };
223
+ }, [isVisible, setVisibility]);
152
224
  var intl = (0, _reactIntlNext.useIntl)();
153
225
  var label = intl.formatMessage(_messages.messages.inlineOverlay);
154
226
  var icon = (0, _react.useMemo)(function () {
155
- var IconComponent = isToolbarOpen ? _chevronUp.default : _chevronDown.default;
227
+ var IconComponent = isSelected ? _chevronUp.default : _chevronDown.default;
156
228
  return (0, _react2.jsx)(IconComponent, {
157
229
  label: label,
158
230
  size: "small",
159
- testId: "".concat(testId, "-").concat(isToolbarOpen ? 'open' : 'close')
231
+ testId: "".concat(testId, "-").concat(isSelected ? 'open' : 'close')
160
232
  });
161
- }, [isToolbarOpen, label, testId]);
162
- return (0, _react2.jsx)("span", {
233
+ }, [isSelected, label, testId]);
234
+ return (0, _react2.jsx)("span", (0, _extends2.default)({}, props, {
163
235
  css: containerStyles,
164
236
  ref: containerRef
165
- }, children, isVisible && (0, _react2.jsx)(_react.default.Fragment, null, (0, _react2.jsx)("span", {
237
+ }), children, isVisible && showOverlay && (0, _react2.jsx)(_react.default.Fragment, null, (0, _react2.jsx)("span", {
166
238
  "aria-hidden": "true",
167
- css: markerStyles,
168
- ref: markerRef
239
+ className: OVERLAY_MARKER_CLASSNAME,
240
+ css: markerStyles
169
241
  }), (0, _react2.jsx)("a", {
242
+ className: OVERLAY_CLASSNAME,
170
243
  css: [overlayStyles, _utils.browser.safari && safariOverlayStyles],
171
244
  style: {
172
245
  marginLeft: -overlayWidth
@@ -176,11 +249,11 @@ var InlineCardOverlay = function InlineCardOverlay(_ref) {
176
249
  onClick: function onClick(e) {
177
250
  return e.preventDefault();
178
251
  },
179
- ref: overlayRef
252
+ tabIndex: -1
180
253
  }, showLabel && (0, _react2.jsx)("span", {
254
+ className: OVERLAY_LABEL_CLASSNAME,
181
255
  css: textStyles,
182
- "data-testid": "".concat(testId, "-label"),
183
- ref: labelRef
256
+ "data-testid": "".concat(testId, "-label")
184
257
  }, label), (0, _react2.jsx)("span", {
185
258
  css: iconStyles
186
259
  }, icon))));
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getOverlayWidths = exports.getInlineCardAvailableWidth = exports.getChildElement = void 0;
7
+ /**
8
+ * Find a child element inside a ref.
9
+ */
10
+ var getChildElement = exports.getChildElement = function getChildElement(ref, selector) {
11
+ return ref.current ? ref.current.querySelector(selector) : undefined;
12
+ };
13
+
14
+ /**
15
+ * Get the available width of the inline card.
16
+ * (Mainly here to make the component unit testable.)
17
+ */
18
+ var getInlineCardAvailableWidth = exports.getInlineCardAvailableWidth = function getInlineCardAvailableWidth(startEl, endEl) {
19
+ var start = startEl.getBoundingClientRect().left;
20
+ var end = endEl.getBoundingClientRect().left;
21
+ return end - start;
22
+ };
23
+
24
+ /**
25
+ * Get max and min width of an overlay.
26
+ * (Mainly here to make the component unit testable.)
27
+ */
28
+ var getOverlayWidths = exports.getOverlayWidths = function getOverlayWidths(overlayEl, labelEl) {
29
+ var max = overlayEl.getBoundingClientRect().width;
30
+ var min = max - labelEl.getBoundingClientRect().width;
31
+ return {
32
+ max: max,
33
+ min: min
34
+ };
35
+ };
@@ -122,6 +122,8 @@ export function InlineCardNodeView(props) {
122
122
  useAlternativePreloader: useAlternativePreloader
123
123
  });
124
124
  }
125
+
126
+ // BEGIN: Awareness (To be revisited in EDM-8508)
125
127
  const editorState = view.state;
126
128
  const linkPosition = getPos && typeof getPos() === 'number' ? getPos() : undefined;
127
129
  const canBeUpgradedToEmbed = !!linkPosition && allowEmbeds ? isEmbedSupportedAtPosition(linkPosition, editorState, 'inline') : false;
@@ -129,6 +131,8 @@ export function InlineCardNodeView(props) {
129
131
  const isPulseEnabled = enableInlineUpgradeFeatures && canBeUpgradedToEmbed;
130
132
  const isOverlayEnabled = enableInlineUpgradeFeatures && (canBeUpgradedToEmbed || canBeUpgradedToBlock);
131
133
  const isSelected = view.state.selection instanceof NodeSelection && ((_view$state$selection = view.state.selection) === null || _view$state$selection === void 0 ? void 0 : (_view$state$selection2 = _view$state$selection.node) === null || _view$state$selection2 === void 0 ? void 0 : _view$state$selection2.type) === view.state.schema.nodes.inlineCard && ((_view$state$selection3 = view.state.selection) === null || _view$state$selection3 === void 0 ? void 0 : _view$state$selection3.from) === getPos();
134
+ // END: Awareness
135
+
132
136
  return /*#__PURE__*/React.createElement(WrappedInlineCardWithAwareness, {
133
137
  node: node,
134
138
  view: view,
@@ -1,4 +1,3 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
1
  /** @jsx jsx */
3
2
  import { memo, useCallback, useMemo, useState } from 'react';
4
3
  import { css, jsx } from '@emotion/react';
@@ -28,16 +27,15 @@ const InlineCard = ({
28
27
  isOverlayEnabled,
29
28
  isPulseEnabled,
30
29
  pluginInjectionApi,
31
- isSelected
30
+ isSelected = false
32
31
  }) => {
33
32
  const {
34
33
  url,
35
34
  data
36
35
  } = node.attrs;
37
36
 
38
- // A complete show/hide logic for the overlay will be implemented
39
- // in EDM-8239 and EDM-8241
40
- const [isOverlayVisible, setIsOverlayVisible] = useState(false);
37
+ // BEGIN: Awareness (To be revisited in EDM-8508)
38
+ const [isHovered, setIsHovered] = useState(false);
41
39
  const linkPosition = useMemo(() => {
42
40
  if (!getPos || typeof getPos === 'boolean') {
43
41
  return undefined;
@@ -63,6 +61,8 @@ const InlineCard = ({
63
61
  if (isSelected && shouldShowToolbarPulse && !isLocalStorageKeyDiscovered(LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR)) {
64
62
  markLocalStorageKeyDiscovered(LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK);
65
63
  }
64
+ // END: Awareness
65
+
66
66
  const scrollContainer = useMemo(() => findOverflowScrollParent(view.dom) || undefined, [view.dom]);
67
67
  const onResolve = useCallback(data => {
68
68
  if (!getPos || typeof getPos === 'boolean') {
@@ -99,10 +99,7 @@ const InlineCard = ({
99
99
  url
100
100
  });
101
101
  }, [onResolve]);
102
- const innerCard = useMemo(() => jsx(InlineCardOverlay, {
103
- isVisible: isOverlayVisible,
104
- url: url
105
- }, jsx(SmartCard, {
102
+ const innerCard = useMemo(() => jsx(SmartCard, {
106
103
  key: url,
107
104
  url: url,
108
105
  data: data,
@@ -113,18 +110,25 @@ const InlineCard = ({
113
110
  onError: onError,
114
111
  inlinePreloaderStyle: useAlternativePreloader ? 'on-right-without-skeleton' : undefined,
115
112
  showServerActions: showServerActions
116
- })), [data, isOverlayVisible, onError, onResolve, scrollContainer, showServerActions, url, useAlternativePreloader]);
117
- const card = useMemo(() => jsx("span", _extends({
113
+ }), [data, onError, onResolve, scrollContainer, showServerActions, url, useAlternativePreloader]);
114
+
115
+ // BEGIN: Awareness (To be revisited in EDM-8508)
116
+ const cardWithOverlay = useMemo(() => shouldShowLinkOverlay ? jsx(InlineCardOverlay, {
117
+ isSelected: isSelected,
118
+ isVisible: isHovered || isSelected,
119
+ onMouseEnter: () => setIsHovered(true),
120
+ onMouseLeave: () => setIsHovered(false),
121
+ url: url
122
+ }, innerCard) : innerCard, [innerCard, isHovered, isSelected, shouldShowLinkOverlay, url]);
123
+ const card = useMemo(() => jsx("span", {
118
124
  css: shouldShowLinkPulse && loaderWrapperStyles,
119
125
  className: "card"
120
- }, shouldShowLinkOverlay ? {
121
- onMouseEnter: () => setIsOverlayVisible(true),
122
- onMouseLeave: () => setIsOverlayVisible(false)
123
- } : {}), shouldShowLinkPulse ? jsx(DiscoveryPulse, {
126
+ }, shouldShowLinkPulse ? jsx(DiscoveryPulse, {
124
127
  localStorageKey: LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK,
125
128
  localStorageKeyExpirationInMs: ONE_DAY_IN_MILLISECONDS,
126
- discoveryMode: 'start'
127
- }, innerCard) : innerCard), [shouldShowLinkPulse, shouldShowLinkOverlay, innerCard]);
129
+ discoveryMode: "start"
130
+ }, cardWithOverlay) : cardWithOverlay), [shouldShowLinkPulse, cardWithOverlay]);
131
+ // END: Awareness
128
132
 
129
133
  // [WS-2307]: we only render card wrapped into a Provider when the value is ready,
130
134
  // otherwise if we got data, we can render the card directly since it doesn't need the Provider
@@ -23,7 +23,7 @@ const getClosestInlineCardPos = (state, editorView, direction) => {
23
23
  left: coord.left,
24
24
  top: direction === 'up' ? coord.top - lookupPixel : coord.bottom + lookupPixel
25
25
  })) === null || _editorView$posAtCoor === void 0 ? void 0 : _editorView$posAtCoor.inside;
26
- if (nearPos) {
26
+ if (typeof nearPos === 'number' && nearPos > -1) {
27
27
  const newNode = state.doc.nodeAt(nearPos);
28
28
  if (newNode) {
29
29
  if (newNode.type !== inlineCardType || findChildren(parent, node => node === newNode, false).length === 0 || newNode === selection.node) {